Skip to content

Commit

Permalink
Fix asyncio event loop init in qml_bridge.py
Browse files Browse the repository at this point in the history
Depending on Python version the file may be imported in a thread and
asyncio only implicitly creates an event loop in the main thread of the
process.  Backend does things which need asyncio so we must ensure an
event loop exists before it is imported.

Fixes mirukana#15
  • Loading branch information
DataBeaver committed May 15, 2020
1 parent 4bae3cf commit 9a6c4b5
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/backend/qml_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,16 @@ class QMLBridge:
"""

def __init__(self) -> None:
try:
self._loop = asyncio.get_event_loop()
except RuntimeError:
self._loop = asyncio.new_event_loop()
asyncio.set_event_loop(self._loop)
self._loop.set_exception_handler(self._loop_exception_handler)

from .backend import Backend
self.backend: Backend = Backend()

self._loop = asyncio.get_event_loop()
self._loop.set_exception_handler(self._loop_exception_handler)

Thread(target=self._start_asyncio_loop).start()


Expand Down

0 comments on commit 9a6c4b5

Please sign in to comment.