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

2021-07-26 Thread Thomas Wouters


Thomas Wouters  added the comment:

This was fixed back in 2018, in fact.

--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2021-07-25 Thread Andrei Kulakov


Andrei Kulakov  added the comment:

3.6 no longer gets bugfixes, so I think this can be closed.

--
nosy: +andrei.avk

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2020-11-04 Thread Brett Cannon


Change by Brett Cannon :


--
nosy:  -brett.cannon

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2018-04-19 Thread Thomas Wouters

Change by Thomas Wouters :


--
pull_requests: +6232

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2018-04-19 Thread Nathaniel Smith

Change by Nathaniel Smith :


--
pull_requests: +6230

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2018-04-18 Thread Thomas Wouters

Change by Thomas Wouters :


--
pull_requests: +6213
stage:  -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2018-04-18 Thread Thomas Wouters

Thomas Wouters  added the comment:

Looks like this was fixed in 3.7 by checking 
PyThreadState_GET()->interp->modules before trying to use it. That leaves the 
crash in 3.6 and earlier, though.

--
stage: patch review -> 

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2018-04-18 Thread Thomas Wouters

Change by Thomas Wouters :


--
keywords: +patch
pull_requests: +6211
stage:  -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2018-04-18 Thread Thomas Wouters

Thomas Wouters  added the comment:

We ran into this at work, with Python 3.6, where it involved extension types 
with a reference to files, with the (open) files being deallocated during 
interpreter exit and raising ResourceWarnings because of that. I tried to 
create a simple reproducer and failed, but I *did* manage to reproduce it in 
2.7:

% cat warningscrash.py
import threading
import warnings

class WarnOnDel(object):
def __del__(self):
warnings.warn("oh no something went wrong", UserWarning)

def do_work():
while True:
w = WarnOnDel()

for i in range(10):
t = threading.Thread(target=do_work)
t.setDaemon(1)
t.start()

% python2 warningscrash.py
warningscrash.py:7: UserWarning: oh no something went wrong
  warnings.warn("oh no something went wrong", UserWarning)
Fatal Python error: PyImport_GetModuleDict: no module dictionary!
Aborted (core dumped)

It's clearly dependent on timing, as even when starting 10 threads it doesn't 
always happen. Starting more threads makes it happen more often (but might 
cause your machine to trash a little). This doesn't reproduce it with Python 
3.6, but I do believe it's possible there, too, but perhaps it requires threads 
that release the GIL for a longer period of time, or do deallocations with less 
overhead.

Python 2.7's warnings module doesn't try to do anything sensible during 
interpreter shutdown, as far as I can tell. Python 3.6's warnings module does, 
a little, but it's still possible to get this crash. The problem is that 
interp->modules (sys.modules) is deleted right before the _warnings module 
tries to access it (with PyImport_GetModuleDict in 
Python/_warnings.c:get_warnings_attr). I think a fix for 3.6 shouldn't be too 
hard, since we can check _Py_Finalizing.

--
nosy: +twouters
versions: +Python 2.7, Python 3.4, Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2016-01-19 Thread Min RK

Changes by Min RK :


Added file: http://bugs.python.org/file41659/main.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2016-01-19 Thread Min RK

Changes by Min RK :


Added file: http://bugs.python.org/file41658/b.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2016-01-19 Thread Min RK

Changes by Min RK :


Added file: http://bugs.python.org/file41657/a.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2016-01-19 Thread Min RK

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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2016-01-19 Thread Matthias Bussonnier

Changes by Matthias Bussonnier :


--
nosy: +mbussonn

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2016-01-19 Thread SilentGhost

Changes by SilentGhost :


--
nosy: +brett.cannon

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com