Skip to content

Commit 9faec8d

Browse files
committed
Unsubscribe from events when worker stops
1 parent b356195 commit 9faec8d

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/blueapi/worker/task_worker.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ def run(self) -> None:
377377
"""
378378
LOGGER.info("Worker starting")
379379
self._ctx.run_engine.state_hook = self._on_state_change # type: ignore
380-
self._ctx.run_engine.subscribe(self._on_document)
380+
subs = self._ctx.run_engine.subscribe(self._on_document)
381381
if self._broadcast_statuses:
382382
self._ctx.run_engine.waiting_hook = self._waiting_hook # type: ignore
383383

@@ -388,6 +388,7 @@ def run(self) -> None:
388388
self._started.clear()
389389
self._stopping.clear()
390390
self._stopped.set()
391+
self._ctx.run_engine.unsubscribe(subs)
391392

392393
@start_as_current_span(TRACER, "defer")
393394
def pause(self, defer=False):

0 commit comments

Comments
 (0)