Visitar URL original
GH-84559: Deprecate fork being the multiprocessing default. by gpshead · Pull Request #100618 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Correct warning stacklevel for Manager.
  • Loading branch information
gpshead committed Jan 1, 2023
commit 99478600da7d30c8dc30b6df6a9533602a762eba
9 changes: 8 additions & 1 deletion Lib/multiprocessing/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,15 @@ def Manager(self):
can be used to create shared objects.
'''
from .managers import SyncManager
m = SyncManager(ctx=self.get_context())
ctx = self.get_context()
m = SyncManager(ctx=ctx)
proc_class = ctx.Process
Comment thread
gpshead marked this conversation as resolved.
Outdated
orig_level = getattr(proc_class, '_ORIG_WARNING_STACKLEVEL', None)
if orig_level:
ctx.Process._warning_stacklevel = 6 # blame mp.Manager()
m.start()
if orig_level:
ctx.Process._warning_stacklevel = orig_level
return m

def Pipe(self, duplex=True):
Expand Down
13 changes: 13 additions & 0 deletions Lib/test/test_multiprocessing_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ def test_default_fork_start_method_warning_pool(self):
self.assertIn("get_context", str(ws[0].message))
self.assertEqual(len(ws), 1, msg=[str(x) for x in ws])

def test_default_fork_start_method_warning_manager(self):
with warnings.catch_warnings(record=True) as ws:
warnings.simplefilter('ignore')
warnings.filterwarnings('always', category=DefaultForkDeprecationWarning)
manager = multiprocessing.Manager() # warning should point here.
manager.shutdown()
self.assertIsInstance(ws[0].message, DefaultForkDeprecationWarning)
self.assertIn(__file__, ws[0].filename)
self.assertEqual(getframeinfo(currentframe()).lineno-4, ws[0].lineno)
self.assertIn("'fork'", str(ws[0].message))
self.assertIn("get_context", str(ws[0].message))
self.assertEqual(len(ws), 1, msg=[str(x) for x in ws])

def test_no_mp_warning_when_using_explicit_fork_context(self):
with warnings.catch_warnings(record=True) as ws:
warnings.simplefilter('ignore')
Expand Down