Debian Codegraph @

cpython27/Lib/test/crashers/warnings_del_crasher.py

raw symbols SCIP
1 """
2 Expose a race in the _warnings module, which is the C backend for the
3 warnings module. The "_warnings" module tries to access attributes of the
4 "warnings" module (because of the API it has to support), but doing so
5 during interpreter shutdown is problematic. Specifically, the call to
6 PyImport_GetModuleDict() in Python/_warnings.c:get_warnings_attr will
7 abort() if the modules dict has already been cleaned up.
8
9 This crasher is timing-dependent, and more threads (NUM_THREADS) may be
10 necessary to expose it reliably on different systems.
11 """
12
13 import threading
14 import warnings
15
16 NUM_THREADS = 10
17
18 class WarnOnDel(object):
19 def __del__(self):
20 warnings.warn("oh no something went wrong", UserWarning)
21
22 def do_work():
23 while True:
24 w = WarnOnDel()
25
26 for i in range(NUM_THREADS):
27 t = threading.Thread(target=do_work)
28 t.setDaemon(1)
29 t.start()