This commit is contained in:
Richard Oudkerk 2013-02-26 13:11:11 +00:00
commit 0320025f17
3 changed files with 46 additions and 6 deletions

View File

@ -10,6 +10,7 @@
import os
import sys
import signal
import errno
from multiprocessing import util, process
@ -109,12 +110,17 @@ if sys.platform != 'win32':
def poll(self, flag=os.WNOHANG):
if self.returncode is None:
try:
pid, sts = os.waitpid(self.pid, flag)
except OSError:
# Child process not yet created. See #1731717
# e.errno == errno.ECHILD == 10
return None
while True:
try:
pid, sts = os.waitpid(self.pid, flag)
except OSError as e:
if e.errno == errno.EINTR:
continue
# Child process not yet created. See #1731717
# e.errno == errno.ECHILD == 10
return None
else:
break
if pid == self.pid:
if os.WIFSIGNALED(sts):
self.returncode = -os.WTERMSIG(sts)

View File

@ -2868,6 +2868,38 @@ class _TestLogging(BaseTestCase):
# logger.warn('foo')
# assert self.__handled
#
# Check that Process.join() retries if os.waitpid() fails with EINTR
#
class _TestPollEintr(BaseTestCase):
ALLOWED_TYPES = ('processes',)
@classmethod
def _killer(cls, pid):
time.sleep(0.5)
os.kill(pid, signal.SIGUSR1)
@unittest.skipUnless(hasattr(signal, 'SIGUSR1'), 'requires SIGUSR1')
def test_poll_eintr(self):
got_signal = [False]
def record(*args):
got_signal[0] = True
pid = os.getpid()
oldhandler = signal.signal(signal.SIGUSR1, record)
try:
killer = self.Process(target=self._killer, args=(pid,))
killer.start()
p = self.Process(target=time.sleep, args=(1,))
p.start()
p.join()
self.assertTrue(got_signal[0])
self.assertEqual(p.exitcode, 0)
killer.join()
finally:
signal.signal(signal.SIGUSR1, oldhandler)
#
# Test to verify handle verification, see issue 3321
#

View File

@ -270,6 +270,8 @@ Core and Builtins
Library
-------
- Issue #17018: Make Process.join() retry if os.waitpid() fails with EINTR.
- Issue #17197: profile/cProfile modules refactored so that code of run() and
runctx() utility functions is not duplicated in both modules.