@@ -509,27 +509,6 @@ def Pipe(duplex=True):
509509 return c1 , c2
510510
511511else :
512- if hasattr (select , 'poll' ):
513- def _poll (fds , timeout ):
514- if timeout is not None :
515- timeout = int (timeout ) * 1000 # timeout is in milliseconds
516- fd_map = {}
517- pollster = select .poll ()
518- for fd in fds :
519- pollster .register (fd , select .POLLIN )
520- if hasattr (fd , 'fileno' ):
521- fd_map [fd .fileno ()] = fd
522- else :
523- fd_map [fd ] = fd
524- ls = []
525- for fd , event in pollster .poll (timeout ):
526- if event & select .POLLNVAL :
527- raise ValueError ('invalid file descriptor %i' % fd )
528- ls .append (fd_map [fd ])
529- return ls
530- else :
531- def _poll (fds , timeout ):
532- return select .select (fds , [], [], timeout )[0 ]
533512
534513 def Pipe (duplex = True ):
535514 '''
@@ -883,6 +862,29 @@ def wait(object_list, timeout=None):
883862
884863else :
885864
865+ if hasattr (select , 'poll' ):
866+ def _poll (fds , timeout ):
867+ if timeout is not None :
868+ timeout = int (timeout ) * 1000 # timeout is in milliseconds
869+ fd_map = {}
870+ pollster = select .poll ()
871+ for fd in fds :
872+ pollster .register (fd , select .POLLIN )
873+ if hasattr (fd , 'fileno' ):
874+ fd_map [fd .fileno ()] = fd
875+ else :
876+ fd_map [fd ] = fd
877+ ls = []
878+ for fd , event in pollster .poll (timeout ):
879+ if event & select .POLLNVAL :
880+ raise ValueError ('invalid file descriptor %i' % fd )
881+ ls .append (fd_map [fd ])
882+ return ls
883+ else :
884+ def _poll (fds , timeout ):
885+ return select .select (fds , [], [], timeout )[0 ]
886+
887+
886888 def wait (object_list , timeout = None ):
887889 '''
888890 Wait till an object in object_list is ready/readable.
@@ -891,12 +893,12 @@ def wait(object_list, timeout=None):
891893 '''
892894 if timeout is not None :
893895 if timeout <= 0 :
894- return select . select (object_list , [], [], 0 )[ 0 ]
896+ return _poll (object_list , 0 )
895897 else :
896898 deadline = time .time () + timeout
897899 while True :
898900 try :
899- return select . select (object_list , [], [], timeout )[ 0 ]
901+ return _poll (object_list , timeout )
900902 except OSError as e :
901903 if e .errno != errno .EINTR :
902904 raise
0 commit comments