File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed
Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change 33from typing import Generic
44from typing_extensions import override
55
6- import anyio
6+ from anyio . lowlevel import checkpoint
77
88from alicebot import Adapter , Event , MessageEvent
99from alicebot .plugin import Plugin
1515]
1616
1717
18+ async def allow_schedule_other_tasks () -> None :
19+ """让出当前任务,允许其他任务执行。"""
20+ for _ in range (1000 ):
21+ await checkpoint ()
22+
23+
1824class FakeAdapter (Adapter [AnyEvent , None ]):
1925 """用于测试的适配器。"""
2026
@@ -37,10 +43,10 @@ async def run(self) -> None:
3743 await self .handle_event (event , handle_get = self .handle_get )
3844
3945 # 发送一个事件后,等待完成必要的处理再发送下一个
40- await anyio . sleep ( 0.01 )
46+ await allow_schedule_other_tasks ( )
4147
4248 # 尽可能让其他任务执行完毕后再退出
43- await anyio . sleep ( 0.01 )
49+ await allow_schedule_other_tasks ( )
4450
4551 self .bot .exit ()
4652
You can’t perform that action at this time.
0 commit comments