Can't send message in child process

I can’t send message in a child process, anything wrong with my code?

import sentry_sdk

from sentry_sdk import capture_message

import threading
import multiprocessing, time

sentry_sdk.init(MY_DNS)

def worker():
print(“worker”)
sentry_sdk.init(MY_DNS)
capture_message(‘Something went wrong’)
time.sleep(10)

th = multiprocessing.Process(target=worker)
th.start()

th.join()

Hi, have you tried initializing the sdk only in the worker?

I tried, result is same. actually I suspect that if the pause time is not long enough, because sometime it will work. According to my google result, it’s a known issue that if the sub-process exit before the message is sent, message will be lost.

The following works for me (inside the worker):

with init(...):
    capture_message(..)

In regular usage we register an atexit handler which would normally take care of sending messages before your process ends. But it seems that this generally doesn’t work when fork is involved.

Alternatively to the with-statement you can do Hub.current.client.close()

thanks, I will try that , I am a newbie to this library. I think I am ok now, because in my real project, my sub-process will just catch exception, process it and sentry should have enough time to send data. the toy example is just to test if it works with subprocess.