Skip to content

Commit 67da894

Browse files
committed
fix for previous commit related to issue 10527 which didn't have the intended effect as per http://bugs.python.org/issue10527#msg179895
1 parent ed9e06c commit 67da894

2 files changed

Lines changed: 26 additions & 24 deletions

File tree

Lib/multiprocessing/connection.py

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -509,27 +509,6 @@ def Pipe(duplex=True):
509509
return c1, c2
510510

511511
else:
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

884863
else:
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

Lib/test/test_multiprocessing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3244,7 +3244,7 @@ def test_wait_integer(self):
32443244
from multiprocessing.connection import wait
32453245

32463246
expected = 3
3247-
sorted_ = lambda l: sorted(l, key=lambda x: isinstance(x, int))
3247+
sorted_ = lambda l: sorted(l, key=lambda x: id(x))
32483248
sem = multiprocessing.Semaphore(0)
32493249
a, b = multiprocessing.Pipe()
32503250
p = multiprocessing.Process(target=self.signal_and_sleep,

0 commit comments

Comments
 (0)