You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
EventDispatcher.stop() hangs when events are still queued #133
EventDispatcher.stop() never returns if two or more events are still in the queue when it's called. MeshCore.disconnect() awaits it first, so disconnect hangs too.
Reproduction
importasynciofrommeshcore.eventsimportEvent, EventDispatcher, EventTypeasyncdefmain():
d=EventDispatcher()
d.subscribe(EventType.OK, lambdae: print("handled", e.payload))
awaitd.start()
awaitasyncio.sleep(0) # the loop is now waiting in queue.get()awaitd.dispatch(Event(EventType.OK, {"n": 1}))
awaitd.dispatch(Event(EventType.OK, {"n": 2}))
awaitd.stop() # prints "handled {'n': 1}", then waits for everprint("stopped")
asyncio.run(main())
Without the sleep(0), a single event dispatched straight after start() is enough. Same on 3.11 and 3.14. (On 3.10 and 3.11, asyncio.wait_for(d.stop(), ...) hides it, because there wait_for runs stop() in a new task and the loop gets to drain the queue first.)
stop() sets self.running = False (L268) and then waits on self.queue.join() (L271).
_process_events() is while self.running: (L210), so after the event in hand it sees running is false and returns.
The events left in the queue are never taken, so task_done() (L245) is never called for them and join() never returns. The cancel() after it (L276) is never reached.
Found while working on #125 (part of #119). I'll send a fix.
Activity