Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import asyncio
- import time
- class class1():
- async def function_inside_class(self):
- await asyncio.sleep(1)
- print("Waited 1 second!")
- async def function_inside_class2(self):
- await asyncio.sleep(5)
- print("Waited 5 second!")
- def tic():
- global _start_time
- _start_time = time.time()
- def tac():
- t_sec = round(time.time() - _start_time)
- (t_min, t_sec) = divmod(t_sec,60)
- (t_hour,t_min) = divmod(t_min,60)
- print('Time passed: {}hour:{}min:{}sec'.format(t_hour,t_min,t_sec))
- object = class1()
- async def main():
- tic()
- await asyncio.wait([
- object.function_inside_class(),
- object.function_inside_class2()
- ])
- tac()
- loop = asyncio.get_event_loop()
- loop.run_until_complete(main())
- loop.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement