You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2020-01-07.12:18:19.602>created_at=<Date2019-10-16.22:46:46.844>labels= ['tests', '3.9']
title='regrtest: use process groups'updated_at=<Date2020-04-14.23:05:24.084>user='https://github.com/vstinner'
When regrtest is interrupted by CTRL+c and regrtest multiprocessing code (-jN command line option) is used, regrtest randomly fails to stop come TestWorkerProcess threads.
The problem is that only the direct child process is kill by SIGKILL. If the test spawns a grandchild process, this one will not be killed.
Moreover, the grandchild process inherits the child process stdout and stderr. But regrtest mltiprocessing uses pipes for the child process stdout and stderr.
At the end, Popen.communicate() hangs randomly in the main regrtest process (in a TestWorkerProcess thread) until the child process *and* the grandchild process completes. Except that the main regrtest does not directly kill the grandchild process.
(1) use Popen() with start_new_session=True: a worker process calls setsid() to create a new process group.
(2) Don't kill worker processes, but kill the process groups of worker processes.
See also bpo-18969: "test suite: enable faulthandler timeout in assert_python". This issue proposes to use killpg() to send a signal to all Python processes spawned by regrtest: trigger faulthandler to dump the Python traceback of all Python threads.
I don't know for sure that this is the cause but both 3.x builds following this commit on my bolen-ubuntu worker (Ubuntu 18.04.3) have had test_pty crash in the first attempt, with the retry succeeding. For example https://buildbot.python.org/all/#/builders/141/builds/2679
In spot checking, the same behavior seems to be occurring on many other non-Windows builders as well, presumably those for which it gets used.
There doesn't seem to be anything useful produced by the first crash. Just an entry for "test_pty crashed (Exit code -1)" in the test log.
I can recreate this manually by running regrtest.py against test_pty. Crashes with any "-j#" option, but fine when run sequentially. Removing the process group change avoids the crash.
With the process group change in place, the trigger point appears to be the final "os.close(master_fd)" in PtyTest.test_basic. Commenting that out avoids the crash.
I don't know for sure that this is the cause but both 3.x builds following this commit on my bolen-ubuntu worker (Ubuntu 18.04.3) have had test_pty crash in the first attempt, with the retry succeeding. For example https://buildbot.python.org/all/#/builders/141/builds/2679
I created bpo-38547: "test_pty fails when using setsid()".
regrtest now calls setsid() when using multiprocessing (-jN), but only in the main branch. It's a nice feature, but I'm not comfortable about backporting it yet. Maybe if tests become too unstable on other branches, we may backport the feature to 3.7 and 3.8.
Activity
vstinner commentedon Oct 16, 2019
Problem.
When regrtest is interrupted by CTRL+c and regrtest multiprocessing code (-jN command line option) is used, regrtest randomly fails to stop come TestWorkerProcess threads.
The problem is that only the direct child process is kill by SIGKILL. If the test spawns a grandchild process, this one will not be killed.
Moreover, the grandchild process inherits the child process stdout and stderr. But regrtest mltiprocessing uses pipes for the child process stdout and stderr.
At the end, Popen.communicate() hangs randomly in the main regrtest process (in a TestWorkerProcess thread) until the child process *and* the grandchild process completes. Except that the main regrtest does not directly kill the grandchild process.
=> see bpo-38207
Solution.
I propose to:
(1) use Popen() with start_new_session=True: a worker process calls setsid() to create a new process group.
(2) Don't kill worker processes, but kill the process groups of worker processes.
Attached PR implements this solution.
vstinner commentedon Oct 16, 2019
Example of the problem: sometimes, interrupting a multiprocessing test hangs. regrtest fails to interrupt a TestWorkerProcess thread.
With my PR, I cannot reproduce the "Waiting for ..." issue anymore.
vstinner commentedon Oct 16, 2019
See also bpo-18969: "test suite: enable faulthandler timeout in assert_python". This issue proposes to use killpg() to send a signal to all Python processes spawned by regrtest: trigger faulthandler to dump the Python traceback of all Python threads.
vstinner commentedon Oct 16, 2019
See also bpo-12413 "make faulthandler dump traceback of child processes" which looks like a duplicate of bpo-18969.
vstinner commentedon Oct 18, 2019
New changeset ecb035c by Victor Stinner in branch 'master':
bpo-38502: regrtest uses process groups if available (GH-16829)
ecb035c
vstinner commentedon Oct 18, 2019
I will wait at least one day to see how buildbots like this change before backporting it to 3.7 and 3.8.
db3l commentedon Oct 18, 2019
I don't know for sure that this is the cause but both 3.x builds following this commit on my bolen-ubuntu worker (Ubuntu 18.04.3) have had test_pty crash in the first attempt, with the retry succeeding. For example https://buildbot.python.org/all/#/builders/141/builds/2679
In spot checking, the same behavior seems to be occurring on many other non-Windows builders as well, presumably those for which it gets used.
There doesn't seem to be anything useful produced by the first crash. Just an entry for "test_pty crashed (Exit code -1)" in the test log.
db3l commentedon Oct 18, 2019
I can recreate this manually by running regrtest.py against test_pty. Crashes with any "-j#" option, but fine when run sequentially. Removing the process group change avoids the crash.
With the process group change in place, the trigger point appears to be the final "os.close(master_fd)" in PtyTest.test_basic. Commenting that out avoids the crash.
vstinner commentedon Oct 21, 2019
I created bpo-38547: "test_pty fails when using setsid()".
vstinner commentedon Jan 7, 2020
The test_pty has been fixed.
regrtest now calls setsid() when using multiprocessing (-jN), but only in the main branch. It's a nice feature, but I'm not comfortable about backporting it yet. Maybe if tests become too unstable on other branches, we may backport the feature to 3.7 and 3.8.
vstinner commentedon Apr 14, 2020
New changeset 67b8a1f by Victor Stinner in branch '3.8':
[3.8] Update libregrtest from master (GH-19516)
67b8a1f
vstinner commentedon Apr 14, 2020
New changeset b894b66 by Victor Stinner in branch '3.7':
Update libregrtest from master (GH-19517)
b894b66