Skip to content

Commit

Permalink
avoid race
Browse files Browse the repository at this point in the history
  • Loading branch information
keithralphs committed Oct 25, 2024
1 parent e61a975 commit 658faa1
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/blueapi/worker/task_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ def mark_task_as_started(event: WorkerEvent, _: str | None) -> None:

LOGGER.info(f"Submitting: {trackable_task}")
try:
sub = self.worker_events.subscribe(mark_task_as_started)
self._context_register[trackable_task.task_id] = get_trace_context()
sub = self.worker_events.subscribe(mark_task_as_started)
""" Cache the current trace context as the one for this task id """
self._task_channel.put_nowait(trackable_task)
task_started.wait(timeout=5.0)
Expand Down Expand Up @@ -332,7 +332,10 @@ def _cycle(self) -> None:
except Exception as err:
self._report_error(err)
finally:
if self._current is not None:
if (
self._current is not None
and self._current.task_id in self._context_register
):
self._context_register.pop(self._current.task_id)

if self._current is not None:
Expand Down

0 comments on commit 658faa1

Please sign in to comment.