cpython: 751371dd4d1c (original) (raw)
Mercurial > cpython
changeset 88640:751371dd4d1c 2.7
Issue #14548: Make multiprocessing finalizers check pid before running to cope with possibility of gc running just after fork. (Backport from 3.x.) [#14548]
Richard Oudkerk roudkerk@google.com | |
---|---|
date | Thu, 23 Jan 2014 00:11:04 +0000 |
parents | d8af233da629 |
children | bcfbab86f49a |
files | Lib/multiprocessing/util.py Misc/NEWS |
diffstat | 2 files changed, 13 insertions(+), 3 deletions(-)[+] [-] Lib/multiprocessing/util.py 12 Misc/NEWS 4 |
line wrap: on
line diff
--- a/Lib/multiprocessing/util.py +++ b/Lib/multiprocessing/util.py @@ -32,6 +32,7 @@
SUCH DAMAGE.
# +import os import itertools import weakref import atexit @@ -184,6 +185,7 @@ class Finalize(object): self._args = args self._kwargs = kwargs or {} self._key = (exitpriority, _finalizer_counter.next())
self._pid = os.getpid()[](#l1.15)
_finalizer_registry[self._key] = self @@ -196,9 +198,13 @@ class Finalize(object): except KeyError: sub_debug('finalizer no longer registered') else:
sub_debug('finalizer calling %s with args %s and kwargs %s',[](#l1.23)
self._callback, self._args, self._kwargs)[](#l1.24)
res = self._callback(*self._args, **self._kwargs)[](#l1.25)
if self._pid != os.getpid():[](#l1.26)
sub_debug('finalizer ignored because different process')[](#l1.27)
res = None[](#l1.28)
else:[](#l1.29)
sub_debug('finalizer calling %s with args %s and kwargs %s',[](#l1.30)
self._callback, self._args, self._kwargs)[](#l1.31)
res = self._callback(*self._args, **self._kwargs)[](#l1.32) self._weakref = self._callback = self._args = \[](#l1.33) self._kwargs = self._key = None[](#l1.34) return res[](#l1.35)
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -38,6 +38,10 @@ Core and Builtins Library ------- +- Issue #14548: Make multiprocessing finalizers check pid before