# HG changeset patch # Parent 65fd991684fa65e31bf4ac5deae8e9b11db150b6 diff -r 65fd991684fa -r 55ec4af1df45 Lib/multiprocessing/util.py --- a/Lib/multiprocessing/util.py Sun Apr 08 13:56:25 2012 +0000 +++ b/Lib/multiprocessing/util.py Thu Apr 12 18:57:10 2012 +0100 @@ -32,6 +32,7 @@ # SUCH DAMAGE. # +import os import functools import itertools import weakref @@ -184,6 +185,7 @@ self._args = args self._kwargs = kwargs or {} self._key = (exitpriority, next(_finalizer_counter)) + self._pid = os.getpid() _finalizer_registry[self._key] = self @@ -200,9 +202,13 @@ 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