Skip to content

Commit 0cbed97

Browse files
committed
tweaked task cleanup on stop to try to fix pytest error
1 parent cd87d2e commit 0cbed97

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

custom_components/pyscript/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,10 @@ async def start_triggers(event):
175175

176176
async def stop_triggers(event):
177177
_LOGGER.debug("stopping triggers")
178-
for global_ctx_name, global_ctx in GlobalContextMgr.items():
179-
if not global_ctx_name.startswith("file."):
180-
continue
178+
for _, global_ctx in GlobalContextMgr.items():
181179
global_ctx.stop()
182180
# tell reaper task to exit (after other tasks are cancelled)
183-
Function.task_cancel(None)
181+
await Function.reaper_stop()
184182

185183
hass.bus.async_listen(EVENT_HOMEASSISTANT_STARTED, start_triggers)
186184
hass.bus.async_listen(EVENT_HOMEASSISTANT_STOP, stop_triggers)

custom_components/pyscript/function.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ async def task_cancel_reaper(reaper_q):
9292
cls.task_reaper_q = asyncio.Queue(0)
9393
cls.task_cancel_repeaer = Function.create_task(task_cancel_reaper(cls.task_reaper_q))
9494

95+
@classmethod
96+
async def reaper_stop(cls):
97+
"""Tell the reaper task to exit by sending a special task None."""
98+
cls.task_cancel(None)
99+
await cls.task_cancel_repeaer
100+
95101
@classmethod
96102
async def async_sleep(cls, duration):
97103
"""Implement task.sleep()."""

0 commit comments

Comments
 (0)