Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import asyncio
- import random
- import traceback
- def something_that_happens_later(future: asyncio.Future):
- if random.randint(0, 1):
- future.set_result('Future is done')
- else:
- future.set_exception(ValueError('Future is fail'))
- async def main():
- my_future = asyncio.Future()
- asyncio.get_event_loop().call_later(2, something_that_happens_later, my_future)
- print('Waiting...')
- try:
- print(await my_future)
- except ValueError:
- traceback.print_exc()
- if __name__ == '__main__':
- asyncio.get_event_loop().run_until_complete(main())
Add Comment
Please, Sign In to add comment