Skip to content

Instantly share code, notes, and snippets.

@vxgmichel
Last active October 19, 2020 15:38
Show Gist options
  • Save vxgmichel/46e7aa46d0da32ce0c647e27df39f7b9 to your computer and use it in GitHub Desktop.
Save vxgmichel/46e7aa46d0da32ce0c647e27df39f7b9 to your computer and use it in GitHub Desktop.
Asyncio long sleep (over 1 day)
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