Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

Catch uncaught exception from thread#723

Open
PierreF wants to merge 1 commit intogetsentry:masterfrom
PierreF:catch-thread-exception
Open

Catch uncaught exception from thread#723
PierreF wants to merge 1 commit intogetsentry:masterfrom
PierreF:catch-thread-exception

Conversation

@PierreF
Copy link
Copy Markdown

@PierreF PierreF commented Jan 14, 2016

Raven use excepthook to catch uncaught exception, but this only work for main thread. If you spawn any other thread (using threading.Thread), any uncaught exception will be catched but threading.Thread and just print on stderr.

There is a known bug on Python that didn't evolved for years : http://bugs.python.org/issue1230540

On this bug, some workaround exists. This PR propose to integrate a workaround in raven client. Like the excepthook, it install an hook for thread when raven client is initialized.

It has the limitation that raven client must be initialized before creating other thread, or the hook won't be activated for that thread.

The following script show the issue: without the PR, the exception is only printed on stderr. With the PR, the exception is sent to Sentry and printed to stderr.

import threading

from raven import Client

def target():
    0 / 0

Client('http://user:pass@localhost:9000/1')
t = threading.Thread(target=target)
t.start()

@mitsuhiko
Copy link
Copy Markdown
Contributor

I think this would need some fine tuning. In the current form that seems dangerous.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants