Skip to content

fix(ws): per-instance event loop for same-process multi-Client#8

Open
liangxp1990 wants to merge 1 commit into
larksuite:mainfrom
liangxp1990:fix/multi-instance-event-loop
Open

fix(ws): per-instance event loop for same-process multi-Client#8
liangxp1990 wants to merge 1 commit into
larksuite:mainfrom
liangxp1990:fix/multi-instance-event-loop

Conversation

@liangxp1990

Copy link
Copy Markdown

ws/client.py used a module-level loop singleton (loop = asyncio.get_event_loop() at import). Client.start() did loop.run_until_complete(_select()) which occupied that single loop indefinitely, so a second Client in the same process collided with "This event loop is already running" — making same-process multi-bot impossible (e.g. agno AgentOS multi-bot pattern, OpenClaw-style multi-account).

Fix: each Client gets its own loop (self._loop = asyncio.new_event_loop() in init) and uses self._loop everywhere (start/_connect/_receive_message_loop/ _schedule_handle_message). Single-Client behavior unchanged; N Clients now coexist in one process, each on its own loop — aligning with OpenClaw (Node) which runs multiple accounts concurrently on one event loop natively.

Verified: two FeishuChannel (two app_id) in one agno AgentOS process both connect (running:true), no "event loop already running".

ws/client.py used a module-level `loop` singleton (loop = asyncio.get_event_loop()
at import). Client.start() did loop.run_until_complete(_select()) which occupied
that single loop indefinitely, so a second Client in the same process collided
with "This event loop is already running" — making same-process multi-bot
impossible (e.g. agno AgentOS multi-bot pattern, OpenClaw-style multi-account).

Fix: each Client gets its own loop (self._loop = asyncio.new_event_loop() in
__init__) and uses self._loop everywhere (start/_connect/_receive_message_loop/
_schedule_handle_message). Single-Client behavior unchanged; N Clients now
coexist in one process, each on its own loop — aligning with OpenClaw (Node)
which runs multiple accounts concurrently on one event loop natively.

Verified: two FeishuChannel (two app_id) in one agno AgentOS process both
connect (running:true), no "event loop already running".
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants