Thomas Wouters <tho...@python.org> 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 <rep...@bugs.python.org>
<https://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