[Python-checkins] cpython (2.7): Issue #14548: Make multiprocessing finalizers check pid before
richard.oudkerk
python-checkins at python.org
Thu Jan 23 01:13:25 CET 2014
http://hg.python.org/cpython/rev/751371dd4d1c
changeset: 88640:751371dd4d1c
branch: 2.7
parent: 88636:d8af233da629
user: Richard Oudkerk <roudkerk at google.com>
date: Thu Jan 23 00:11:04 2014 +0000
summary:
Issue #14548: Make multiprocessing finalizers check pid before
running to cope with possibility of gc running just after fork.
(Backport from 3.x.)
files:
Lib/multiprocessing/util.py | 12 +++++++++---
Misc/NEWS | 4 ++++
2 files changed, 13 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
@@ -32,6 +32,7 @@
# SUCH DAMAGE.
#
+import os
import itertools
import weakref
import atexit
@@ -184,6 +185,7 @@
self._args = args
self._kwargs = kwargs or {}
self._key = (exitpriority, _finalizer_counter.next())
+ self._pid = os.getpid()
_finalizer_registry[self._key] = self
@@ -196,9 +198,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
@@ -38,6 +38,10 @@
Library
-------
+- Issue #14548: Make multiprocessing finalizers check pid before
+ running to cope with possibility of gc running just after fork.
+ (Backport from 3.x.)
+
- Issue #20262: Warnings are raised now when duplicate names are added in the
ZIP file or too long ZIP file comment is truncated.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list