mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Issue #14548: Make multiprocessing finalizers check pid before running
This protects from possibilty of gc running just after fork.
This commit is contained in:
parent
692130a231
commit
739ae5692e
2 changed files with 12 additions and 3 deletions
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import functools
|
import functools
|
||||||
|
import os
|
||||||
import itertools
|
import itertools
|
||||||
import weakref
|
import weakref
|
||||||
import atexit
|
import atexit
|
||||||
|
@ -161,6 +162,7 @@ class Finalize(object):
|
||||||
self._args = args
|
self._args = args
|
||||||
self._kwargs = kwargs or {}
|
self._kwargs = kwargs or {}
|
||||||
self._key = (exitpriority, next(_finalizer_counter))
|
self._key = (exitpriority, next(_finalizer_counter))
|
||||||
|
self._pid = os.getpid()
|
||||||
|
|
||||||
_finalizer_registry[self._key] = self
|
_finalizer_registry[self._key] = self
|
||||||
|
|
||||||
|
@ -177,9 +179,13 @@ class Finalize(object):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
sub_debug('finalizer no longer registered')
|
sub_debug('finalizer no longer registered')
|
||||||
else:
|
else:
|
||||||
sub_debug('finalizer calling %s with args %s and kwargs %s',
|
if self._pid != os.getpid():
|
||||||
self._callback, self._args, self._kwargs)
|
sub_debug('finalizer ignored because different process')
|
||||||
res = self._callback(*self._args, **self._kwargs)
|
res = None
|
||||||
|
else:
|
||||||
|
sub_debug('finalizer calling %s with args %s and kwargs %s',
|
||||||
|
self._callback, self._args, self._kwargs)
|
||||||
|
res = self._callback(*self._args, **self._kwargs)
|
||||||
self._weakref = self._callback = self._args = \
|
self._weakref = self._callback = self._args = \
|
||||||
self._kwargs = self._key = None
|
self._kwargs = self._key = None
|
||||||
return res
|
return res
|
||||||
|
|
|
@ -44,6 +44,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #14548: Make multiprocessing finalizers check pid before
|
||||||
|
running to cope with possibility of gc running just after fork.
|
||||||
|
|
||||||
- Issue #14863: Update the documentation of os.fdopen() to reflect the
|
- Issue #14863: Update the documentation of os.fdopen() to reflect the
|
||||||
fact that it's only a thin wrapper around open() anymore.
|
fact that it's only a thin wrapper around open() anymore.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue