Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.9.5 (2025-05-27)

### Changes

- Initialize the event loop inside the dedicated thread to avoid clashing with other event loop in the main thread.

## 0.9.4 (2025-05-24)

### Changes
Expand Down
10 changes: 8 additions & 2 deletions python/mujinwebstackclient/controllerwebclientraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,22 @@ def __repr__(self):
class BackgroundThread(object):
_thread: threading.Thread # A thread to run the event loop
_eventLoop: asyncio.AbstractEventLoop # Event loop that is running so that client can add coroutine
_eventLoopReadyEvent: threading.Event # An event that signals the event loop is ready

def __init__(self):
# create a new event loop in a background thread
self._eventLoop = asyncio.new_event_loop()
self._eventLoopReadyEvent = threading.Event()
self._thread = threading.Thread(target=self._RunEventLoop)
self._thread.start()
# block and wait for the signal to make sure the event loop is created and set in the _thread
self._eventLoopReadyEvent.wait()

def _RunEventLoop(self):
# create a new event loop in a background thread
self._eventLoop = asyncio.new_event_loop()
# set the created loop as the current event loop for this thread
asyncio.set_event_loop(self._eventLoop)
# signals that the event loop is now ready
self._eventLoopReadyEvent.set()
self._eventLoop.run_forever()

def RunCoroutine(self, coroutine: Callable):
Expand Down
2 changes: 1 addition & 1 deletion python/mujinwebstackclient/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '0.9.4'
__version__ = '0.9.5'

# Do not forget to update CHANGELOG.md