summaryrefslogtreecommitdiffstats
path: root/Lib/multiprocessing
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-11-19 20:11:20 (GMT)
committerGitHub <noreply@github.com>2019-11-19 20:11:20 (GMT)
commit829593a9262e67c72167c6cb20d383203b2ea410 (patch)
tree9ea3f69d5837981978129ad4201752f7344b6117 /Lib/multiprocessing
parent6c3b471c8c0bfd49c664d8ee7e95da3710fd6069 (diff)
downloadcpython-829593a9262e67c72167c6cb20d383203b2ea410.zip
cpython-829593a9262e67c72167c6cb20d383203b2ea410.tar.gz
cpython-829593a9262e67c72167c6cb20d383203b2ea410.tar.bz2
bpo-38707: Fix for multiprocessing.Process MainThread.native_id (GH-17088)
This PR implements a fix for `multiprocessing.Process` objects; the error occurs when Processes are created using either `fork` or `forkserver` as the `start_method`. In these instances, the `MainThread` of the newly created `Process` object retains all attributes from its parent's `MainThread` object, including the `native_id` attribute. The resulting behavior is such that the new process' `MainThread` captures an incorrect/outdated `native_id` (the parent's instead of its own). This change forces the Process object to update its `native_id` attribute during the bootstrap process. cc @vstinner https://bugs.python.org/issue38707 Automerge-Triggered-By: @pitrou (cherry picked from commit c6b20be85c0de6f2355c67ae6e7e578941275cc0) Co-authored-by: Jake Tesler <jake.tesler@gmail.com>
Diffstat (limited to 'Lib/multiprocessing')
-rw-r--r--Lib/multiprocessing/process.py2
1 files changed, 2 insertions, 0 deletions
diff --git a/Lib/multiprocessing/process.py b/Lib/multiprocessing/process.py
index c62c826..be13c07 100644
--- a/Lib/multiprocessing/process.py
+++ b/Lib/multiprocessing/process.py
@@ -301,6 +301,8 @@ class BaseProcess(object):
_current_process = self
_parent_process = _ParentProcess(
self._parent_name, self._parent_pid, parent_sentinel)
+ if threading._HAVE_THREAD_NATIVE_ID:
+ threading.main_thread()._set_native_id()
try:
util._finalizer_registry.clear()
util._run_after_forkers()