Skip to content
Merged
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
cleanup warn stacklevel logic
  • Loading branch information
gpshead committed Dec 31, 2022
commit 4c8cc342ffc789c46180f0bdb29722085ee7edf1
25 changes: 13 additions & 12 deletions Lib/multiprocessing/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,20 +326,21 @@ def _repopulate_pool_static(ctx, Process, processes, pool, inqueue,
wrap_exception))
w.name = w.name.replace('Process', 'PoolWorker')
w.daemon = True
if _warn := getattr(w, '_warn', None): # GH-84559
# Hacky, but BaseProcess._Popen does everything via the class
# using static or class methods with no instance. The way
# multiprocessing APIs get used, a concurrency mess here
# with a Pool() being constructed at the same time as other
# threads are calling Process.start() is highly unlikely.
# If so: The oddball application gets the warning attributed
proc_class = w.__class__
orig_level = getattr(proc_class, '_ORIG_WARNING_STACKLEVEL', None)
if orig_level:
# Direct the GH-84559 warning to a useful place.
# Hacky, but BaseProcess._Popen does everything via class
# and static methods with no instance. The way multiprocessing
# APIs get used, a concurrency mess here with a Pool() being
# constructed at the same time other threads are calling
# Process.start() is highly unlikely.
# If so: That oddball application gets the warning attributed
# to an unusual spot in the stack on occasion.
process_class = w.__class__
process_class._warning_stacklevel = 8 # blame mp.Pool()
proc_class._warning_stacklevel = 8 # blame mp.Pool()
w.start()
if _warn:
process_class._warning_stacklevel = (
process_class._ORIG_WARNING_STACKLEVEL)
if orig_level:
proc_class._warning_stacklevel = orig_level
pool.append(w)
util.debug('added worker')

Expand Down