parent_test: Refactor `wait_for_child`

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
pull/1389/head
Marc Hartmayer 3 weeks ago
parent fdaf09c4d6
commit 2d9e90acf9

@ -2,7 +2,6 @@ import errno
import fcntl
import os
import signal
import sys
import time
import unittest
@ -21,23 +20,6 @@ except NameError:
from io import FileIO as file
def wait_for_child(pid, timeout=1.0):
deadline = mitogen.core.now() + timeout
while timeout < mitogen.core.now():
try:
target_pid, status = os.waitpid(pid, os.WNOHANG)
if target_pid == pid:
return
except OSError:
e = sys.exc_info()[1]
if e.args[0] == errno.ECHILD:
return
time.sleep(0.05)
assert False, "wait_for_child() timed out"
@mitogen.core.takes_econtext
def call_func_in_sibling(ctx, econtext, sync_sender):
recv = ctx.call_async(time.sleep, 99999)
@ -106,7 +88,7 @@ class ReapChildTest(testlib.RouterMixin, testlib.TestCase):
self.assertRaises(mitogen.core.TimeoutError,
lambda: conn.connect(context=mitogen.core.Context(None, 1234))
)
wait_for_child(conn.proc.pid)
testlib.wait_for_child(conn.proc.pid)
e = self.assertRaises(OSError,
lambda: os.kill(conn.proc.pid, 0)
)
@ -165,7 +147,7 @@ class ContextTest(testlib.RouterMixin, testlib.TestCase):
local = self.router.local()
pid = local.call(os.getpid)
local.shutdown(wait=True)
wait_for_child(pid)
testlib.wait_for_child(pid)
self.assertRaises(OSError, lambda: os.kill(pid, 0))

@ -86,6 +86,23 @@ if faulthandler is not None:
mitogen.core.LOG.propagate = True
def wait_for_child(pid, timeout=1.0):
deadline = mitogen.core.now() + timeout
while timeout < mitogen.core.now():
try:
target_pid, status = os.waitpid(pid, os.WNOHANG)
if target_pid == pid:
return
except OSError:
e = sys.exc_info()[1]
if e.args[0] == errno.ECHILD:
return
time.sleep(0.05)
assert False, "wait_for_child() timed out"
def base_executable(executable=None):
'''Return the path of the Python executable used to create the virtualenv.
'''

Loading…
Cancel
Save