Skip to content

Commit 11da869

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 1804271 commit 11da869

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
@@ -271,7 +272,12 @@ async def _target(self) -> None:
271272
while True:
272273
callback = await self._queue.get()
273274
try:
274-
callback()
275+
if inspect.iscoroutinefunction(callback):
276+
# Callback is an async coroutine, need to await it
277+
await callback()
278+
else:
279+
# Callback is a sync function, need to call it
280+
callback()
275281
except Exception:
276282
logger.error("Failed processing job", exc_info=True)
277283
finally:

0 commit comments

Comments
 (0)