cpython: 59567c117b0e (original) (raw)
Mercurial > cpython
changeset 77141:59567c117b0e
Issue #14548: Make multiprocessing finalizers check pid before running This protects from possibilty of gc running just after fork. [#14548]
Richard Oudkerk shibturn@gmail.com | |
---|---|
date | Fri, 25 May 2012 13:54:53 +0100 |
parents | 57d6265beaaa |
children | 70ec1f671c19 |
files | Lib/multiprocessing/util.py Misc/NEWS |
diffstat | 2 files changed, 12 insertions(+), 3 deletions(-)[+] [-] Lib/multiprocessing/util.py 12 Misc/NEWS 3 |
line wrap: on
line diff
--- 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()[](#l1.15)
_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',[](#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 @@ -44,6 +44,9 @@ Core and Builtins Library ------- +- Issue #14548: Make multiprocessing finalizers check pid before