Created
October 24, 2023 14:01
-
-
Save k4nar/f525e690a6f1f73ee74d8b878e56746d to your computer and use it in GitHub Desktop.
See what happens when a thread segfault in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import faulthandler | |
import threading | |
import time | |
def oups(): | |
import ctypes | |
# Segfault! | |
ctypes.string_at(0) | |
def wait_and_die(): | |
time.sleep(0.5) | |
oups() | |
faulthandler.enable() | |
threads = [ | |
threading.Thread(target=time.sleep, args=(10,)), | |
threading.Thread(target=wait_and_die), | |
threading.Thread(target=time.sleep, args=(10,)), | |
threading.Thread(target=time.sleep, args=(10,)), | |
] | |
for thread in threads: | |
thread.start() | |
for thread in threads: | |
thread.join( |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: