Skip to content

Commit 8b98d2a

Browse files
authored
Add a crasher to Lib/test for issue #26153. This crasher doesn't crash (#6518)
Python 3.6, although I've seen the same crash in 3.6 (when involving extension types and more complicated threading setups).
1 parent db10742 commit 8b98d2a

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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()

0 commit comments

Comments
 (0)