diff options
author | Richard Oudkerk <shibturn@gmail.com> | 2012-05-25 12:54:53 (GMT) |
---|---|---|
committer | Richard Oudkerk <shibturn@gmail.com> | 2012-05-25 12:54:53 (GMT) |
commit | 739ae5692ebc7daaf1297d8e775e552bdb05f3fe (patch) | |
tree | 938db3278cff75874689de6939c812a0b1659fcd /Lib/multiprocessing | |
parent | 692130a2315545ff7155c364d39c25ad1cb52210 (diff) | |
download | cpython-739ae5692ebc7daaf1297d8e775e552bdb05f3fe.zip cpython-739ae5692ebc7daaf1297d8e775e552bdb05f3fe.tar.gz cpython-739ae5692ebc7daaf1297d8e775e552bdb05f3fe.tar.bz2 |
Issue #14548: Make multiprocessing finalizers check pid before running
This protects from possibilty of gc running just after fork.
Diffstat (limited to 'Lib/multiprocessing')
-rw-r--r-- | Lib/multiprocessing/util.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/Lib/multiprocessing/util.py b/Lib/multiprocessing/util.py index f0d7e11..16ded51 100644 --- a/Lib/multiprocessing/util.py +++ b/Lib/multiprocessing/util.py @@ -9,6 +9,7 @@ import sys import functools +import os import itertools import weakref import atexit @@ -161,6 +162,7 @@ class Finalize(object): self._args = args self._kwargs = kwargs or {} self._key = (exitpriority, next(_finalizer_counter)) + self._pid = os.getpid() _finalizer_registry[self._key] = self @@ -177,9 +179,13 @@ class Finalize(object): except KeyError: sub_debug('finalizer no longer registered') 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) + if self._pid != os.getpid(): + sub_debug('finalizer ignored because different process') + 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._kwargs = self._key = None return res |