Kaydet (Commit) e8a57b98 authored tarafından Richard Oudkerk's avatar Richard Oudkerk

Issue #14548: Make multiprocessing finalizers check pid before

running to cope with possibility of gc running just after fork.
(Backport from 3.x.)
üst 70fdd79c
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
# SUCH DAMAGE. # SUCH DAMAGE.
# #
import os
import itertools import itertools
import weakref import weakref
import atexit import atexit
...@@ -184,6 +185,7 @@ class Finalize(object): ...@@ -184,6 +185,7 @@ class Finalize(object):
self._args = args self._args = args
self._kwargs = kwargs or {} self._kwargs = kwargs or {}
self._key = (exitpriority, _finalizer_counter.next()) self._key = (exitpriority, _finalizer_counter.next())
self._pid = os.getpid()
_finalizer_registry[self._key] = self _finalizer_registry[self._key] = self
...@@ -196,9 +198,13 @@ class Finalize(object): ...@@ -196,9 +198,13 @@ class Finalize(object):
except KeyError: except KeyError:
sub_debug('finalizer no longer registered') sub_debug('finalizer no longer registered')
else: else:
sub_debug('finalizer calling %s with args %s and kwargs %s', if self._pid != os.getpid():
self._callback, self._args, self._kwargs) sub_debug('finalizer ignored because different process')
res = self._callback(*self._args, **self._kwargs) 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._weakref = self._callback = self._args = \
self._kwargs = self._key = None self._kwargs = self._key = None
return res return res
......
...@@ -38,6 +38,10 @@ Core and Builtins ...@@ -38,6 +38,10 @@ Core and Builtins
Library 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 - Issue #20262: Warnings are raised now when duplicate names are added in the
ZIP file or too long ZIP file comment is truncated. ZIP file or too long ZIP file comment is truncated.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment