[2.7] bpo-31160: Backport reap_children fixes from master to 2.7 (#3063)
* bpo-31160: regrtest now reaps child processes (#3044) Add a post_test_cleanup() function which currently only calls support.reap_children(). (cherry picked from commite3510d74aa
) * bpo-31160: test_tempfile: Fix reap_children() warning (#3056) TestRandomNameSequence.test_process_awareness() now calls os.waitpid() to avoid leaking a zombie process. (cherry picked from commit6c8c2943d9
)
This commit is contained in:
parent
693790817a
commit
1247e2cda5
|
@ -1172,6 +1172,9 @@ class saved_test_environment:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def post_test_cleanup():
|
||||||
|
test_support.reap_children()
|
||||||
|
|
||||||
def runtest_inner(test, verbose, quiet, huntrleaks=False, pgo=False, testdir=None):
|
def runtest_inner(test, verbose, quiet, huntrleaks=False, pgo=False, testdir=None):
|
||||||
test_support.unload(test)
|
test_support.unload(test)
|
||||||
if verbose:
|
if verbose:
|
||||||
|
@ -1205,6 +1208,7 @@ def runtest_inner(test, verbose, quiet, huntrleaks=False, pgo=False, testdir=Non
|
||||||
refleak = dash_R(the_module, test, indirect_test,
|
refleak = dash_R(the_module, test, indirect_test,
|
||||||
huntrleaks)
|
huntrleaks)
|
||||||
test_time = time.time() - start_time
|
test_time = time.time() - start_time
|
||||||
|
post_test_cleanup()
|
||||||
finally:
|
finally:
|
||||||
sys.stdout = save_stdout
|
sys.stdout = save_stdout
|
||||||
except test_support.ResourceDenied, msg:
|
except test_support.ResourceDenied, msg:
|
||||||
|
|
|
@ -141,12 +141,15 @@ class test__RandomNameSequence(TC):
|
||||||
try:
|
try:
|
||||||
pid = os.fork()
|
pid = os.fork()
|
||||||
if not pid:
|
if not pid:
|
||||||
|
# child process
|
||||||
os.close(read_fd)
|
os.close(read_fd)
|
||||||
os.write(write_fd, next(self.r).encode("ascii"))
|
os.write(write_fd, next(self.r).encode("ascii"))
|
||||||
os.close(write_fd)
|
os.close(write_fd)
|
||||||
# bypass the normal exit handlers- leave those to
|
# bypass the normal exit handlers- leave those to
|
||||||
# the parent.
|
# the parent.
|
||||||
os._exit(0)
|
os._exit(0)
|
||||||
|
|
||||||
|
# parent process
|
||||||
parent_value = next(self.r)
|
parent_value = next(self.r)
|
||||||
child_value = os.read(read_fd, len(parent_value)).decode("ascii")
|
child_value = os.read(read_fd, len(parent_value)).decode("ascii")
|
||||||
finally:
|
finally:
|
||||||
|
@ -157,6 +160,10 @@ class test__RandomNameSequence(TC):
|
||||||
os.kill(pid, signal.SIGKILL)
|
os.kill(pid, signal.SIGKILL)
|
||||||
except EnvironmentError:
|
except EnvironmentError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# Read the process exit status to avoid zombie process
|
||||||
|
os.waitpid(pid, 0)
|
||||||
|
|
||||||
os.close(read_fd)
|
os.close(read_fd)
|
||||||
os.close(write_fd)
|
os.close(write_fd)
|
||||||
self.assertNotEqual(child_value, parent_value)
|
self.assertNotEqual(child_value, parent_value)
|
||||||
|
|
Loading…
Reference in New Issue