Python SDK -- No event received for error occurring in a separate thread

Hi,

I have noticed that we do not receive events for errors occurring on threads created using threading (Python & Python SDK) within a Flask application (we use the Sentry Flask integration).

import sentry_sdk
sentry_sdk.init(
    dsn="dsn_url"
)

def error_func():
    print([][0])

if __name__ == "__main__":
    import threading
    thread = threading.Thread(target=error_func)
    thread.start()
    while True:
        pass

Would you know if there is any simple way to make the SDK correctly report the error event? I’d rather not have to run a try except within my threads or things like that.

Your example runs correctly for me. What are you observing with this example?

Hi untitaker,

The issue is that no event is received on Sentry for the exception that occurs on the other thread.

Do you see any output at all, such as the traceback of the background thread? FWIW I had to add a time.sleep(0) in your while-loop because the background thread would otherwise be starved in some sense.

And to be clear, which Python version is this?

Hi,

Yes, I see a traceback:


Traceback (most recent call last):

File "/Users/Konrad/anaconda3/lib/python3.6/threading.py", line 916, in _bootstrap_inner

self.run()

File "/Users/Konrad/anaconda3/lib/python3.6/threading.py", line 864, in run

self._target(*self._args, **self._kwargs)

File « /path", line 8, in error_func

print([][0])

IndexError: list index out of range```

Using PyCharm.

Python 3.6.3

<img apple-inline="yes" id="B0777006-355C-4341-AF61-714AB7E9E0D4" src="cid:7E3580AE-AC44-4DE6-BCDA-5821DC4E41DF@stationf.co" class="">

(Attachment PastedGraphic-3.tiff is missing)

Hi,

Yes, I see a traceback:


Traceback (most recent call last):

File "/Users/Konrad/anaconda3/lib/python3.6/threading.py", line 916, in _bootstrap_inner

self.run()

File "/Users/Konrad/anaconda3/lib/python3.6/threading.py", line 864, in run

self._target(*self._args, **self._kwargs)

File « /path", line 8, in error_func

print([][0])

IndexError: list index out of range```

Using PyCharm.

Python 3.6.3

Please make sure it’s not PyCharm interfering with this by launching e.g. from console. I can’t put more debugging efforts into this as it stands.

Also your attachment went missing. I believe this doesn’t work with reply-by-email.

Sorry that was my signature!
I just ran it from console and it doesn’t work: no event received. If I raise an exception in the main thread, I do receive an event.

You receive the event fine when testing on your side?

Hmm yes I do.

Could you try this instead of providing a DSN:

init(transport=print)

This just prints out the event to the console instead of sending it. If that doesn’t work something else is broken.

Hi untitaker,

Seems like my version of sentry_sdk was not up to date.

I updated and I receive the event now.

I apologise for wasting your time, I should have checked. :frowning:

Thanks a lot for the help.

1 Like