如何取消asyncio的循环。稍后调用_()?

2024-10-02 08:30:50 发布

您现在位置:Python中文网/ 问答频道 /正文

如果Ischedule a callback using ^{}(或使用loop.call_at(),其行为方式相同),是否可以取消其执行

为什么??比如说,我计划从现在开始一分钟后运行一些东西。但是,由于某些条件,代码决定中止该执行(因为不再需要它),或者决定将其重新安排到另一个时间。问题是如何使用Python的asyncio实现它

如果您熟悉JavaScript,我正在寻找setTimeout()clearTimeout()的等价物


Tags: 代码loopasyncio方式callback时间javascriptcall
1条回答
网友
1楼 · 发布于 2024-10-02 08:30:50

从链接的docs中:

An instance of asyncio.TimerHandle is returned which can be used to cancel the callback.

从{}的{a2}开始,一个{}的超类:

cancel()

Cancel the callback. If the callback has already been canceled or executed, this method has no effect.

所以只需调用句柄的cancel方法

相关问题 更多 >

    热门问题