classification
Title: test_mymanager_context() of test_multiprocessing_spawn: manager._process.exitcode=-15 on x86 Windows7 3.x
Type: Stage: resolved
Components: Tests, Windows Versions: Python 3.8, Python 3.7, Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: davin, miss-islington, paul.moore, steve.dower, tim.golden, vstinner, zach.ware
Priority: normal Keywords: patch

Created on 2017-05-12 22:30 by vstinner, last changed 2018-06-27 20:25 by vstinner. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 7968 merged vstinner, 2018-06-27 15:25
PR 7969 merged miss-islington, 2018-06-27 16:19
PR 7970 merged miss-islington, 2018-06-27 16:20
Messages (10)
msg293585 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-05-12 22:30
http://buildbot.python.org/all/builders/x86%20Windows7%203.x/builds/601/steps/test/logs/stdio

======================================================================
FAIL: test_mymanager_context (test.test_multiprocessing_spawn.WithManagerTestMyManager)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\cygwin\home\db3l\buildarea\3.x.bolen-windows7\build\lib\test\_test_multiprocessing.py", line 2232, in test_mymanager_context
    self.assertEqual(manager._process.exitcode, 0)
AssertionError: -15 != 0

----------------------------------------------------------------------
Ran 277 tests in 667.577s

FAILED (failures=1, skipped=24)
test test_multiprocessing_spawn failed
msg293717 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-05-15 15:48
> manager._process.exitcode == -15

-15 is -signal.SIGTERM and comes from Popen.wait() of multiprocessing.popen_spawn_win32.

            res = _winapi.WaitForSingleObject(int(self._handle), msecs)
            if res == _winapi.WAIT_OBJECT_0:
                code = _winapi.GetExitCodeProcess(self._handle)
                if code == TERMINATE:
                    code = -signal.SIGTERM

The process exited and its exit code is 0x10000 (TERMINATE).

I understand that Popen.terminate() of multiprocessing.popen_spawn_win32 was called.

BaseManager.start() registers a finalizer: _finalize_manager(). This method sends a "shutdown" message to the process and then gives 1.0 second to the process to complete. If the process doesn't complete in 1 second, .terminate() is called.

1 second is kind of arbitrary: it depends on the system load. We should give more time to the manager to complete, or accept -signal.SIGTERM as a "valid" exit code.

I see different options:

* Shutdown the manager in test_multiprocessing and give more time to the manager to complete
* Make the timeout configurable
* Allow -signal.SIGTERM exit code in test_mymanager_context()
msg302470 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-09-18 16:19
Similar issue: bpo-31510.
msg320592 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-06-27 15:24
The bug can easily be reproduced on Linux using this change:

diff --git a/Lib/multiprocessing/managers.py b/Lib/multiprocessing/managers.py
index 04df26bac6..3d952407c2 100644
--- a/Lib/multiprocessing/managers.py
+++ b/Lib/multiprocessing/managers.py
@@ -649,7 +649,7 @@ class BaseManager(object):
             except Exception:
                 pass
 
-            process.join(timeout=1.0)
+            process.join(timeout=0.0)
             if process.is_alive():
                 util.info('manager still alive')
                 if hasattr(process, 'terminate'):
msg320593 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-06-27 15:28
Python 2.7 terminates the manager process if it takes longer than 200 ms to stop (Python 3 uses a limit of 1 second), but test_multiprocessing doesn't test the exit code of the manager process and so Python 2.7 is not impacted by this bug.
msg320594 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-06-27 15:29
> I see different options: (...) * Allow -signal.SIGTERM exit code in test_mymanager_context()

When I discussed with Davin, he told me that it's an acceptable solution.

So I wrote the PR 7968 to implement this trivial fix.
msg320599 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-06-27 16:18
New changeset fbd7172325e6ce55b6d5d3d7603e4c1c8a219cb8 by Victor Stinner in branch 'master':
bpo-30356: Fix test_mymanager_context() of multiprocessing (GH-7968)
https://github.com/python/cpython/commit/fbd7172325e6ce55b6d5d3d7603e4c1c8a219cb8
msg320600 - (view) Author: miss-islington (miss-islington) Date: 2018-06-27 16:38
New changeset 34f2935dca7bb20cd87e42dc41985cc3d688a735 by Miss Islington (bot) in branch '3.7':
bpo-30356: Fix test_mymanager_context() of multiprocessing (GH-7968)
https://github.com/python/cpython/commit/34f2935dca7bb20cd87e42dc41985cc3d688a735
msg320602 - (view) Author: miss-islington (miss-islington) Date: 2018-06-27 16:45
New changeset a599323fc7661668a01e9fbb0d2369e62941bdf1 by Miss Islington (bot) in branch '3.6':
bpo-30356: Fix test_mymanager_context() of multiprocessing (GH-7968)
https://github.com/python/cpython/commit/a599323fc7661668a01e9fbb0d2369e62941bdf1
msg320612 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-06-27 20:25
I fixed the test in 3.6, 3.7 and master branches.
History
Date User Action Args
2018-06-27 20:25:47vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg320612

stage: patch review -> resolved
2018-06-27 16:45:04miss-islingtonsetmessages: + msg320602
2018-06-27 16:38:39miss-islingtonsetnosy: + miss-islington
messages: + msg320600
2018-06-27 16:20:21miss-islingtonsetpull_requests: + pull_request7578
2018-06-27 16:19:31miss-islingtonsetpull_requests: + pull_request7577
2018-06-27 16:18:20vstinnersetmessages: + msg320599
2018-06-27 15:29:22vstinnersetmessages: + msg320594
2018-06-27 15:28:07vstinnersetmessages: + msg320593
versions: + Python 3.6, Python 3.8
2018-06-27 15:25:42vstinnersetkeywords: + patch
stage: patch review
pull_requests: + pull_request7576
2018-06-27 15:24:11vstinnersetmessages: + msg320592
2017-09-18 16:19:44vstinnersetmessages: + msg302470
2017-05-15 15:48:38vstinnersetmessages: + msg293717
2017-05-12 22:30:23vstinnercreate