[Python-checkins] cpython: Issue #14548: Make multiprocessing finalizers check pid before running
richard.oudkerk
python-checkins at python.org
Fri May 25 14:58:21 CEST 2012
http://hg.python.org/cpython/rev/59567c117b0e
changeset: 77141:59567c117b0e
user: Richard Oudkerk <shibturn at gmail.com>
date: Fri May 25 13:54:53 2012 +0100
summary:
Issue #14548: Make multiprocessing finalizers check pid before running
This protects from possibilty of gc running just after fork.
files:
Lib/multiprocessing/util.py | 12 +++++++++---
Misc/NEWS | 3 +++
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/Lib/multiprocessing/util.py b/Lib/multiprocessing/util.py
--- 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 @@
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 @@
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
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -44,6 +44,9 @@
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
fact that it's only a thin wrapper around open() anymore.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list