Skip to content

Commit 9477a13

Browse files
Improved contextvars support
1 parent acea47f commit 9477a13

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

yatq/worker/runner.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,17 @@ async def _handle_task(self, wrapper, queue) -> None:
125125
return
126126

127127
try:
128-
coro = task_job.process()
128+
# Wrapping coroutine in asyncio.task to copy contextvars
129+
process_task = asyncio.create_task(task_job.process())
129130
except Exception:
130131
LOGGER.exception("Failed to create job coroutine")
131132
await queue.fail_task(wrapper)
132133
return
133134

134135
LOGGER.info("Starting job")
135136
try:
136-
await coro
137+
await process_task
138+
process_task.result()
137139
except Exception:
138140
LOGGER.exception("Exception in job")
139141
wrapper.task.result = {"traceback": traceback.format_exc()}

0 commit comments

Comments
 (0)