Last active
October 19, 2020 15:38
-
-
Save vxgmichel/46e7aa46d0da32ce0c647e27df39f7b9 to your computer and use it in GitHub Desktop.
Asyncio long sleep (over 1 day)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
async def long_sleep(arg): | |
hours = 60*60 | |
async def bg(): | |
while True: | |
await asyncio.sleep(12 * hours) | |
task = asyncio.create_task(bg()) | |
try: | |
await asyncio.sleep(arg) | |
finally: | |
task.cancel() | |
async def main(): | |
# Sleep for 50 days | |
await long_sleep(60*60*24*50) | |
if __name__ == '__main__': | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment