This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: weakref spewing exceptions during finalization when combined with multiprocessing
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.7, Python 3.6, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: lukasz.langa Nosy List: Warwick Chapman, lukasz.langa, methane, pitrou, python-dev
Priority: normal Keywords: 3.5regression, 3.6regression

Created on 2017-02-10 04:35 by lukasz.langa, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
mod1.py lukasz.langa, 2017-02-10 07:36
mod2.py lukasz.langa, 2017-02-10 07:36
Pull Requests
URL Status Linked Edit
PR 2958 merged methane, 2017-07-31 10:35
Messages (12)
msg287475 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2017-02-10 04:35
Antoine, #28427 introduces a regression. When used with multiprocessing, the WeakValueDictionary in `multiprocessing.util._afterfork_registry` causes the `remove()` to be invoked during `atexit` and then `sys.meta_path` is None, lots of things is None, including the global `_remove_dead_weakref`.

In effect, I'm getting spew like this:

Exception ignored in: <function WeakValueDictionary.__init__.<locals>.remove at 0x7fb2b905e2f0>
Traceback (most recent call last):
  File "/usr/local/fbcode/gcc-4.9-glibc-2.20-fb/lib/python3.6/weakref.py", line 112, in remove
TypeError: 'NoneType' object is not callable
Exception ignored in: <function WeakValueDictionary.__init__.<locals>.remove at 0x7fb2b905e2f0>
Traceback (most recent call last):
  File "/usr/local/fbcode/gcc-4.9-glibc-2.20-fb/lib/python3.6/weakref.py", line 112, in remove
TypeError: 'NoneType' object is not callable
Exception ignored in: <function WeakValueDictionary.__init__.<locals>.remove at 0x7fb2b905e2f0>
Traceback (most recent call last):
  File "/usr/local/fbcode/gcc-4.9-glibc-2.20-fb/lib/python3.6/weakref.py", line 112, in remove
TypeError: 'NoneType' object is not callable
Exception ignored in: <function WeakValueDictionary.__init__.<locals>.remove at 0x7fb2b905e2f0>
Traceback (most recent call last):
  File "/usr/local/fbcode/gcc-4.9-glibc-2.20-fb/lib/python3.6/weakref.py", line 112, in remove
TypeError: 'NoneType' object is not callable

When debugged, this 'NoneType' is `_remove_dead_weakref` (weakref.py:117).

I'm working on a smaller repro, unfortunately this happens as part of a rather large multiprocessing app so this might take a while. Just wanted to let you know, maybe you'll know right away what the problem is.
msg287479 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2017-02-10 07:36
I have a pretty minimal repro. You'll have to download both `mod1.py` and `mod2.py` and execute `python3.6 mod1.py`. You'll see:

Exception ignored in: <function WeakValueDictionary.__init__.<locals>.remove at 0x7fcb56b09400>
Traceback (most recent call last):
  File "/usr/local/fbcode/gcc-4.9-glibc-2.20-fb/lib/python3.6/weakref.py", line 117, in remove
TypeError: 'NoneType' object is not callable

I can reproduce this both on CentOS 7 and macOS Sierra. I don't quite understand what makes this particular combination of instructions in the modules trigger the problem, I'd appreciate some explanation. AFAICT any additional simplification to the two modules makes it stop producing the spew.

Note: the spew doesn't happen with 3.6.0, only with master because it's directly caused by the missing global after the change in #28427.
msg287482 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2017-02-10 08:20
New changeset 2cb530243943 by Łukasz Langa in branch '3.5':
Fix #29519: weakref spewing exceptions during interp finalization
https://hg.python.org/cpython/rev/2cb530243943

New changeset c5267272e66a by Łukasz Langa in branch '3.6':
Merge 3.5 (fix #29519)
https://hg.python.org/cpython/rev/c5267272e66a

New changeset e91ec62da088 by Łukasz Langa in branch 'default':
Merge 3.6 (fix #29519)
https://hg.python.org/cpython/rev/e91ec62da088
msg287483 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2017-02-10 08:22
Given that the weakref behavior during shutdown with the repro was identical in 3.6.0, as well as in 3.5.2 and earlier, I patched this by binding the name to a local, therefore making it usable also during finalization.
msg287487 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2017-02-10 09:00
New changeset 6c961c5a5396ef125dbbc47c060272a5d12c1646 by Łukasz Langa in branch 'master':
Fix #29519: weakref spewing exceptions during interp finalization
https://github.com/python/cpython/commit/6c961c5a5396ef125dbbc47c060272a5d12c1646

New changeset 39279a07e8fc7bc14dcb948d970c12dbbf65ff40 by Łukasz Langa in branch 'master':
Merge 3.5 (fix #29519)
https://github.com/python/cpython/commit/39279a07e8fc7bc14dcb948d970c12dbbf65ff40

New changeset 8d6fcedf53048ff53cde91f7a55c1583456fa15e by Łukasz Langa in branch 'master':
Merge 3.6 (fix #29519)
https://github.com/python/cpython/commit/8d6fcedf53048ff53cde91f7a55c1583456fa15e
msg287488 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2017-02-10 09:00
New changeset 6c961c5a5396ef125dbbc47c060272a5d12c1646 by Łukasz Langa in branch '3.5':
Fix #29519: weakref spewing exceptions during interp finalization
https://github.com/python/cpython/commit/6c961c5a5396ef125dbbc47c060272a5d12c1646
msg287489 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2017-02-10 09:00
New changeset 6c961c5a5396ef125dbbc47c060272a5d12c1646 by Łukasz Langa in branch '3.6':
Fix #29519: weakref spewing exceptions during interp finalization
https://github.com/python/cpython/commit/6c961c5a5396ef125dbbc47c060272a5d12c1646

New changeset 39279a07e8fc7bc14dcb948d970c12dbbf65ff40 by Łukasz Langa in branch '3.6':
Merge 3.5 (fix #29519)
https://github.com/python/cpython/commit/39279a07e8fc7bc14dcb948d970c12dbbf65ff40
msg299550 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2017-07-31 10:38
[gsutil](https://github.com/GoogleCloudPlatform/gsutil) shows massive "Exception ... ignored" message from this regression.
https://twitter.com/minimum2scp/status/890021408482316289

I think we should backport this fix to Python 2.7.14.
msg299572 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2017-07-31 17:52
New changeset 3e37f4a11547a226c3c2f8bd612510465db397b9 by Łukasz Langa (INADA Naoki) in branch '2.7':
bpo-29519: weakref spewing exceptions during interp finalization (#2958)
https://github.com/python/cpython/commit/3e37f4a11547a226c3c2f8bd612510465db397b9
msg307487 - (view) Author: Warwick Chapman (Warwick Chapman) Date: 2017-12-03 06:28
Will this be released in 2.x as suggested by inada.naoki?
msg307516 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2017-12-03 14:53
It seems it is merged in 2.7.14.
But I can't find this in changelog of 2.7.14.

https://raw.githubusercontent.com/python/cpython/c707893f9cee870bba8364b3a06eb9cfa3b80e58/Misc/NEWS
msg307518 - (view) Author: Warwick Chapman (Warwick Chapman) Date: 2017-12-03 16:18
Ditto.

On Sun, 03 Dec 2017 at 16:53, INADA Naoki <report@bugs.python.org> wrote:

>
> INADA Naoki <songofacandy@gmail.com> added the comment:
>
> It seems it is merged in 2.7.14.
> But I can't find this in changelog of 2.7.14.
>
>
> https://raw.githubusercontent.com/python/cpython/c707893f9cee870bba8364b3a06eb9cfa3b80e58/Misc/NEWS
>
> ----------
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue29519>
> _______________________________________
>
-- 
-- Warwick Bruce Chapman | 083 7797 094 | http://wa.rwick.com
History
Date User Action Args
2022-04-11 14:58:43adminsetgithub: 73705
2017-12-03 16:18:39Warwick Chapmansetmessages: + msg307518
2017-12-03 14:53:06methanesetmessages: + msg307516
2017-12-03 06:28:50Warwick Chapmansetnosy: + Warwick Chapman
messages: + msg307487
2017-07-31 17:52:48lukasz.langasetmessages: + msg299572
2017-07-31 10:38:33methanesetnosy: + methane

messages: + msg299550
versions: + Python 2.7
2017-07-31 10:35:42methanesetpull_requests: + pull_request3006
2017-02-10 09:00:29python-devsetmessages: + msg287489
2017-02-10 09:00:27python-devsetmessages: + msg287488
2017-02-10 09:00:24python-devsetmessages: + msg287487
2017-02-10 08:22:49lukasz.langasetstatus: open -> closed
messages: + msg287483

assignee: pitrou -> lukasz.langa
resolution: fixed
stage: resolved
2017-02-10 08:20:41python-devsetnosy: + python-dev
messages: + msg287482
2017-02-10 07:36:41lukasz.langasetfiles: + mod2.py
2017-02-10 07:36:31lukasz.langasetfiles: + mod1.py

messages: + msg287479
2017-02-10 04:35:06lukasz.langacreate