Skip to content

Commit 7edbbaf

Browse files
committed
fix(worker): Check if callbacks from worker queue are coroutines or functions
Add a check to see wheter callbacks are awaitable coroutines or functions, as coroutines need to be awaited. GH-4581
1 parent fb0ad18 commit 7edbbaf

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

sentry_sdk/worker.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import threading
55
import asyncio
6+
import inspect
67

78
from time import sleep, time
89
from sentry_sdk._queue import Queue, FullError
@@ -255,7 +256,12 @@ async def _target(self) -> None:
255256
while True:
256257
callback = await self._queue.get()
257258
try:
258-
callback()
259+
if inspect.iscoroutinefunction(callback):
260+
# Callback is an async coroutine, need to await it
261+
await callback()
262+
else:
263+
# Callback is a sync function, need to call it
264+
callback()
259265
except Exception:
260266
logger.error("Failed processing job", exc_info=True)
261267
finally:

0 commit comments

Comments
 (0)