Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[3.8] bpo-38707: Fix for multiprocessing.Process MainThread.native_id (GH-17088) #17261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions 2 Lib/multiprocessing/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ def _bootstrap(self, parent_sentinel=None):
_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()
Expand Down
22 changes: 22 additions & 0 deletions 22 Lib/test/_test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,28 @@ def test_process(self):
self.assertNotIn(p, self.active_children())
close_queue(q)

@unittest.skipUnless(threading._HAVE_THREAD_NATIVE_ID, "needs native_id")
def test_process_mainthread_native_id(self):
if self.TYPE == 'threads':
self.skipTest('test not appropriate for {}'.format(self.TYPE))

current_mainthread_native_id = threading.main_thread().native_id

q = self.Queue(1)
p = self.Process(target=self._test_process_mainthread_native_id, args=(q,))
p.start()

child_mainthread_native_id = q.get()
p.join()
close_queue(q)

self.assertNotEqual(current_mainthread_native_id, child_mainthread_native_id)

@classmethod
def _test_process_mainthread_native_id(cls, q):
mainthread_native_id = threading.main_thread().native_id
q.put(mainthread_native_id)

@classmethod
def _sleep_some(cls):
time.sleep(100)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
``MainThread.native_id`` is now correctly reset in child processes spawned using :class:`multiprocessing.Process`, instead of retaining the parent's value.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.