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 <rep...@bugs.python.org>
<http://bugs.python.org/issue26153>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to