Sentry and multiprocessing?
See original GitHub issueI can’t get multiprocessing spawned worker functions to work with sentry when the worker functions raises an exception.
With below code, I expect both of the spawned worker_function to separately send logs to sentry when the ZeroDivisionError is raised. However, sentry doesn’t appear to send any logs at all. Am I missing something, or this is not how it works. Cheers.
import multiprocessing
dsn = 'https://xxx:yyy@sentry.io/zzzz'
def worker_function():
from raven import Client
client = Client(dsn)
print("worker crashes")
1 / 0
def manager_function():
workers_count = 2
workers = [multiprocessing.Process(target=worker_function) for i in range(workers_count)]
for worker in workers:
worker.start()
manager_function()
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:6 (2 by maintainers)
Top Results From Across the Web
How to configure sentry to send exception from process ...
Sentry works on an async event based model and killing a process just ... captureException() time.sleep(10) import multiprocessing from ...
Read more >Multi-Process Apps for Android - Sentry Documentation
Learn how to automatically initialize the SDK in non-main processes.
Read more >Leave a reply - Server 24/7
/snap/sentry/usr/lib/python2.7/multiprocessing/synchronize.py”, line 75, in __init__ sl = self._semlock = _multiprocessing.SemLock(kind, value, ...
Read more >2031293 – Review Request: python-django-q - Red Hat Bugzilla
Bug 2031293 - Review Request: python-django-q - A multiprocessing ... SQS, MongoDB or ORM - Rollbar and Sentry support Fedora Account System ...
Read more >multiprocessing-utils - PyPI
Multiprocessing utilities. Shared locks. “Shared” version of the standard Lock() and RLock() classes found in the multiprocessing/threading modules.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
A solution can be found below. I monkeypatched multiprocessing run, then used the synchronous transport (the async doesn’t work, because it needs to send the pending request when the process ends, but the hook isn’t there).
Sentry handling exceptions by default works by using
sys.excepthook
, which doesn’t work with threading and multiprocessing due to python issue 1230540. Workarounds exist but a bit tricky. Wrapping your code in a try and usingclient.CaptureException
should work fine. A long term fix is already on our radar.