Usage
aiocron provide a decorator to run function at time:
>>> import aiocron
>>> import asyncio
>>>
>>> @aiocron.crontab('*/30 * * * *')
... async def attime():
... print('run')
...
>>> asyncio.get_event_loop().run_forever()
You can also use it as an object:
>>> @aiocron.crontab('1 9 * * 1-5', start=False)
... async def attime():
... print('run')
...
>>> attime.start()
>>> asyncio.get_event_loop().run_forever()
Your function still be available at attime.func
You can also await a crontab. In this case, your coroutine can accept arguments:
>>> @aiocron.crontab('0 9,10 * * * mon,fri', start=False)
... async def attime(i):
... print('run %i' % i)
...
>>> async def once():
... try:
... res = await attime.next(1)
... except Exception as e:
... print('It failed (%r)' % e)
... else:
... print(res)
...
>>> asyncio.get_event_loop().run_forever()
Finally you can use it as a sleep coroutine. The following will wait until next hour:
>>> await crontab('0 * * * *').next()
If you don’t like the decorator magic you can set the function by yourself:
>>> cron = crontab('0 * * * *', func=yourcoroutine, start=False)
Notice that unlike standard unix crontab you can specify seconds at the 6th position.
aiocron use croniter. Refer to it’s documentation to know more about crontab format.
Release files for aiocron 1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| aiocron-1.7.tar.gz | 16.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aiocron-1.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 20.7 kB
Release files / aiocron-1.7.tar.gz
| Download URL | aiocron-1.7.tar.gz |
|---|---|
| Size | 16.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ad7d3b9bd88897934ffd18937ff235ab9fb01358280fd40e01461fd5f76348bd
|
|
BLAKE2b-256 checksum How to use checksums |
b237b2029981b2d0d6343f586af569502467683fd449ad27dcdf9d96f6ea096f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.14.0 pkginfo/1.4.2 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.3
|
Release files / aiocron-1.7-py3-none-any.whl
| Download URL | aiocron-1.7-py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f06d7b84b86d6cb7156c01e640b4122da86afaa4873c6bcf79e57c4762e48789
|
|
BLAKE2b-256 checksum How to use checksums |
f37fb3088fa213048b1908016f6dc291f5e1a47f384e48c8c3d6440bb7ccbd24
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.14.0 pkginfo/1.4.2 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.3
|