Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

weakref spewing exceptions during finalization when combined with multiprocessing #73705

Closed
ambv opened this issue Feb 10, 2017 · 12 comments
Closed
Assignees
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@ambv
Copy link
Contributor

ambv commented Feb 10, 2017

BPO 29519
Nosy @pitrou, @methane, @ambv
PRs
  • [2.7] bpo-29519: weakref spewing exceptions during interp finalization #2958
  • Files
  • mod1.py
  • mod2.py
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/ambv'
    closed_at = <Date 2017-02-10.08:22:49.348>
    created_at = <Date 2017-02-10.04:35:06.699>
    labels = ['3.7', 'type-bug', 'library']
    title = 'weakref spewing exceptions during finalization when combined with multiprocessing'
    updated_at = <Date 2017-12-03.16:18:39.687>
    user = 'https://github.com/ambv'

    bugs.python.org fields:

    activity = <Date 2017-12-03.16:18:39.687>
    actor = 'Warwick Chapman'
    assignee = 'lukasz.langa'
    closed = True
    closed_date = <Date 2017-02-10.08:22:49.348>
    closer = 'lukasz.langa'
    components = ['Library (Lib)']
    creation = <Date 2017-02-10.04:35:06.699>
    creator = 'lukasz.langa'
    dependencies = []
    files = ['46617', '46618']
    hgrepos = []
    issue_num = 29519
    keywords = ['3.5regression', '3.6regression']
    message_count = 12.0
    messages = ['287475', '287479', '287482', '287483', '287487', '287488', '287489', '299550', '299572', '307487', '307516', '307518']
    nosy_count = 5.0
    nosy_names = ['pitrou', 'methane', 'lukasz.langa', 'python-dev', 'Warwick Chapman']
    pr_nums = ['2958']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue29519'
    versions = ['Python 2.7', 'Python 3.5', 'Python 3.6', 'Python 3.7']

    @ambv
    Copy link
    Contributor Author

    ambv commented Feb 10, 2017

    Antoine, bpo-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.

    @ambv ambv added 3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Feb 10, 2017
    @ambv
    Copy link
    Contributor Author

    ambv commented Feb 10, 2017

    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 bpo-28427.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Feb 10, 2017

    New changeset 2cb530243943 by Łukasz Langa in branch '3.5':
    Fix bpo-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 bpo-29519)
    https://hg.python.org/cpython/rev/c5267272e66a

    New changeset e91ec62da088 by Łukasz Langa in branch 'default':
    Merge 3.6 (fix bpo-29519)
    https://hg.python.org/cpython/rev/e91ec62da088

    @ambv
    Copy link
    Contributor Author

    ambv commented Feb 10, 2017

    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.

    @ambv ambv closed this as completed Feb 10, 2017
    @ambv ambv assigned ambv and unassigned pitrou Feb 10, 2017
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Feb 10, 2017

    New changeset 6c961c5a5396ef125dbbc47c060272a5d12c1646 by Łukasz Langa in branch 'master':
    Fix bpo-29519: weakref spewing exceptions during interp finalization
    6c961c5

    New changeset 39279a07e8fc7bc14dcb948d970c12dbbf65ff40 by Łukasz Langa in branch 'master':
    Merge 3.5 (fix bpo-29519)
    39279a0

    New changeset 8d6fcedf53048ff53cde91f7a55c1583456fa15e by Łukasz Langa in branch 'master':
    Merge 3.6 (fix bpo-29519)
    8d6fced

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Feb 10, 2017

    New changeset 6c961c5a5396ef125dbbc47c060272a5d12c1646 by Łukasz Langa in branch '3.5':
    Fix bpo-29519: weakref spewing exceptions during interp finalization
    6c961c5

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Feb 10, 2017

    New changeset 6c961c5a5396ef125dbbc47c060272a5d12c1646 by Łukasz Langa in branch '3.6':
    Fix bpo-29519: weakref spewing exceptions during interp finalization
    6c961c5

    New changeset 39279a07e8fc7bc14dcb948d970c12dbbf65ff40 by Łukasz Langa in branch '3.6':
    Merge 3.5 (fix bpo-29519)
    39279a0

    @methane
    Copy link
    Member

    methane commented Jul 31, 2017

    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.

    @ambv
    Copy link
    Contributor Author

    ambv commented Jul 31, 2017

    New changeset 3e37f4a by Łukasz Langa (INADA Naoki) in branch '2.7':
    bpo-29519: weakref spewing exceptions during interp finalization (bpo-2958)
    3e37f4a

    @WarwickChapman
    Copy link
    Mannequin

    WarwickChapman mannequin commented Dec 3, 2017

    Will this be released in 2.x as suggested by inada.naoki?

    @methane
    Copy link
    Member

    methane commented Dec 3, 2017

    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

    @WarwickChapman
    Copy link
    Mannequin

    WarwickChapman mannequin commented Dec 3, 2017

    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

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants