Skip to content

Commit

Permalink
inputhook: improve stdin_ready()
Browse files Browse the repository at this point in the history
 - move select and msvcrt imports in the function itself
   as they're only needed there
 - switch on os.name for platform dependent code
 - for unknow platforms, assume there's something to read
  • Loading branch information
cboos committed Oct 9, 2011
1 parent 42c877c commit a761793
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions IPython/lib/inputhook.py
Expand Up @@ -18,10 +18,6 @@
import os
import sys
import warnings
if os.name == 'posix':
import select
elif sys.platform == 'win32':
import msvcrt

#-----------------------------------------------------------------------------
# Constants
Expand All @@ -43,13 +39,16 @@

def stdin_ready():
if os.name == 'posix':
import select
infds, outfds, erfds = select.select([sys.stdin],[],[],0)
if infds:
return True
else:
return False
elif sys.platform == 'win32':
elif os.name == 'nt':
import msvcrt
return msvcrt.kbhit()
return True # assume there's something so that we won't wait forever


#-----------------------------------------------------------------------------
Expand Down

0 comments on commit a761793

Please sign in to comment.