Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import asyncio
- SCHEDULE_PERIOD = 60*60
- USERS = []
- async def fetch_from_makaka():
- result = None
- await asyncio.sleep(15) # emulate some work
- return result
- async def telega_send(user, data):
- await asyncio.sleep(2) # emulate some work
- async def notify_users(data):
- coros = [telega_send(u, data) for u in USERS]
- _ = await asyncio.gather(*coros)
- async def periodic():
- while True:
- print('Start periodic makaka fetch')
- result = await fetch_from_makaka()
- await notify_users(result)
- await asyncio.sleep(SCHEDULE_PERIOD)
- def stop():
- task.cancel()
- if __name__ == "__main__":
- task = asyncio.Task(periodic())
- loop = asyncio.get_event_loop()
- loop.call_later(5, stop)
- try:
- loop.run_until_complete(task)
- except asyncio.CancelledError:
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement