Skip to content

Instantly share code, notes, and snippets.

@joshp123
Last active December 12, 2018 16:14
Show Gist options
  • Save joshp123/dcc715563cb87863b40f0e8abb5f231b to your computer and use it in GitHub Desktop.
Save joshp123/dcc715563cb87863b40f0e8abb5f231b to your computer and use it in GitHub Desktop.
Bare raise inside thread causes segfault
import threading
import time
import logging
logging.basicConfig()
log = logging.Logger(__name__)
class CrashyThread(threading.Thread):
def run(self):
try:
log.warning("hello from crashy thread {}")
raise
except Exception:
log.warning("hello")
return
def main():
t = CrashyThread()
t.daemon = True
t.start()
time.sleep(10)
log.warning("hello from main thread")
if __name__ == "__main__":
main()
@joshp123
Copy link
Author

$ python test.py
hello from crashy thread {}
[1]    2399 segmentation fault  python test.py

vs

cat test.py | sed 's/raise/raise RuntimeError/' | python
hello from crashy thread {}
hello
hello from main thread

@djvdorp
Copy link

djvdorp commented Oct 25, 2018

@joshp123 this was Python v3.6.4 only?

@joshp123
Copy link
Author

Some specific version of python (3.4.x?) I think. It was fixed in later versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment