Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions raven/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import logging
import os
import sys
import threading
import time
import uuid
import warnings
Expand Down Expand Up @@ -183,6 +184,7 @@ def __init__(self, dsn=None, raise_send_errors=False, transport=None,

if install_sys_hook:
self.install_sys_hook()
self.install_thread_hook()

def set_dsn(self, dsn=None, transport=None):
if dsn is None and os.environ.get('SENTRY_DSN'):
Expand Down Expand Up @@ -217,6 +219,26 @@ def handle_exception(*exc_info):
__excepthook__(*exc_info)
sys.excepthook = handle_exception

def install_thread_hook(self):
"""
Workaround for sys.excepthook thread bug, http://bugs.python.org/issue1230540
"""
init_old = threading.Thread.__init__
raven_self = self
def init(self, *args, **kwargs):
init_old(self, *args, **kwargs)
run_old = self.run
def run_with_except_hook(*args, **kw):
try:
run_old(*args, **kw)
except (KeyboardInterrupt, SystemExit):
raise
except:
raven_self.captureException(exc_info=sys.exc_info())
raise
self.run = run_with_except_hook
threading.Thread.__init__ = init

@classmethod
def register_scheme(cls, scheme, transport_class):
cls._registry.register_scheme(scheme, transport_class)
Expand Down