Merge branch 'HKUDS:main' into coding-plan

This commit is contained in:
ouyangwulin
2026-03-05 17:47:41 +08:00
committed by GitHub

View File

@@ -290,16 +290,28 @@ class FeishuChannel(BaseChannel):
log_level=lark.LogLevel.INFO log_level=lark.LogLevel.INFO
) )
# Start WebSocket client in a separate thread with reconnect loop # Start WebSocket client in a separate thread with reconnect loop.
# A dedicated event loop is created for this thread so that lark_oapi's
# module-level `loop = asyncio.get_event_loop()` picks up an idle loop
# instead of the already-running main asyncio loop, which would cause
# "This event loop is already running" errors.
def run_ws(): def run_ws():
while self._running: import time
try: import lark_oapi.ws.client as _lark_ws_client
self._ws_client.start() ws_loop = asyncio.new_event_loop()
except Exception as e: asyncio.set_event_loop(ws_loop)
logger.warning("Feishu WebSocket error: {}", e) # Patch the module-level loop used by lark's ws Client.start()
if self._running: _lark_ws_client.loop = ws_loop
import time try:
time.sleep(5) while self._running:
try:
self._ws_client.start()
except Exception as e:
logger.warning("Feishu WebSocket error: {}", e)
if self._running:
time.sleep(5)
finally:
ws_loop.close()
self._ws_thread = threading.Thread(target=run_ws, daemon=True) self._ws_thread = threading.Thread(target=run_ws, daemon=True)
self._ws_thread.start() self._ws_thread.start()