[issue26153] PyImport_GetModuleDict: no module dictionary! when `__del__` triggers a warning

Min RK report at bugs.python.org
Tue Jan 19 07:14:30 EST 2016


New submission from Min RK:

PyImport_GetModuleDict: no module dictionary! can be raised during interpreter shutdown if a `__del__` method results in a warning. This only happens on Python 3.5.

The prompting case is IPython 4.0.2 and traitlets 4.1.0. An IPython ExtensionManager calls `self.shell.on_trait_change` during its `__del__` to unregister a listener. That `on_trait_change` method is deprecated, and tries to display a DeprecationWarning. The call to `warnings.warn results in:

    Fatal Python error: PyImport_GetModuleDict: no module dictionary!

There appear to be races involved, because the crash happens with inconsistent frequency, sometimes quite rarely.

I've tried to put together a simple minimal test case, but I cannot reproduce the crash outside of IPython. I can, however, reproduce inconsistent behavior where a UserWarning displayed during `__del__` sometimes fails with

    ImportError: import of 'linecache' halted; None in sys.modules

and sometimes the exact same code succeeds, showing the error:

    ~/dev/tmp/del-warn/a.py:9: DeprecationWarning: I don't cleanup anymore
      self.b.cleanup()

and sometimes it shows the warning but not the frame

    ~/dev/tmp/del-warn/a.py:9: DeprecationWarning: I don't cleanup anymore

----------
components: Interpreter Core
messages: 258586
nosy: minrk
priority: normal
severity: normal
status: open
title: PyImport_GetModuleDict: no module dictionary! when `__del__` triggers a warning
type: crash
versions: Python 3.5

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26153>
_______________________________________


More information about the Python-bugs-list mailing list