Skip to content

Commit

Permalink
Fix #289 Updated event loop property in busylight.lights.taskable.Tas…
Browse files Browse the repository at this point in the history
…kableMixin

As I understand it, when lights are activated in a thread other than
the main thread there is not a default async event loop available and
asyncio.get_event_loop raises a RuntimeError. I've modified the
property TaskableMixin.event_loop to catch RuntimeError and create an
event loop.
  • Loading branch information
JnyJny committed Nov 25, 2023
1 parent 6683529 commit 6c8945f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion busylight/lights/taskable.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from typing import Any, Awaitable, Dict, Optional

from loguru import logger


class TaskableMixin:
"""This mixin class is designed to associate and manage
Expand All @@ -18,7 +20,13 @@ def event_loop(self):
return self._event_loop
except AttributeError:
pass
self._event_loop = asyncio.get_event_loop()
try:
self._event_loop = asyncio.get_event_loop()
except Exception as error:
logger.debug("get_event_loop raised {error}")
self._event_loop = asyncio.new_event_loop()
asyncio.set_event_loop(self._event_loop)

return self._event_loop

@property
Expand Down

0 comments on commit 6c8945f

Please sign in to comment.