This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author twouters
Recipients brett.cannon, mbussonn, minrk, twouters
Date 2018-04-18.13:59:21
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1524059961.74.0.682650639539.issue26153@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2018-04-18 13:59:21twouterssetrecipients: + twouters, brett.cannon, minrk, mbussonn
2018-04-18 13:59:21twouterssetmessageid: <1524059961.74.0.682650639539.issue26153@psf.upfronthosting.co.za>
2018-04-18 13:59:21twouterslinkissue26153 messages
2018-04-18 13:59:21twouterscreate