Schedule
callback to be called after the given delay number of seconds (can be
either an int or a float).
An instance of asyncio.TimerHandle is returned which can be used to
cancel the callback.
callback will be called exactly once. If two callbacks are scheduled
for exactly the same time, the order in which they are called is
undefined.
The optional positional args will be passed to the callback when it is
called. If you want the callback to be called with keyword arguments
use functools.partial().
An optional keyword-only context argument allows specifying a custom
contextvars.Context for the callback to run in. The current context is
used when no context is provided.
Changed in version 3.7: The context keyword-only parameter was added.
See PEP 567 for more details.
Changed in version 3.8: In Python 3.7 and earlier with the default
event loop implementation, the delay could not exceed one day. This
has been fixed in Python 3.8.
这将适用于python3。你知道吗
如果您熟悉asyncio,可以使用event loopcall\u later函数。你知道吗
示例(Source):
您可以使用芹菜在一定的延迟后运行任务。你知道吗
你可以在这里了解更多
http://docs.celeryproject.org/en/master/userguide/calling.html#eta-and-countdown
在我的生产代码中,我更喜欢APScheduler而不是芹菜,因为它提供了许多关于运行具有特定延迟或在特定日期的作业的设置(因此您只需将
timedelta(hours=2)
添加到datetime.utcnow()
)看看吧: https://apscheduler.readthedocs.io/en/stable/
相关问题 更多 >
编程相关推荐