Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2021
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. import asyncio
  2. import time
  3.  
  4. class class1():
  5.     async def function_inside_class(self):
  6.         await asyncio.sleep(1)
  7.         print("Waited 1 second!")
  8.  
  9.     async def function_inside_class2(self):
  10.         await asyncio.sleep(5)
  11.         print("Waited 5 second!")
  12.  
  13. def tic():
  14.     global _start_time
  15.     _start_time = time.time()
  16.  
  17. def tac():
  18.     t_sec = round(time.time() - _start_time)
  19.     (t_min, t_sec) = divmod(t_sec,60)
  20.     (t_hour,t_min) = divmod(t_min,60)
  21.     print('Time passed: {}hour:{}min:{}sec'.format(t_hour,t_min,t_sec))
  22.  
  23. object = class1()
  24.  
  25.  
  26. async def main():
  27.     tic()
  28.     await asyncio.wait([
  29.         object.function_inside_class(),
  30.         object.function_inside_class2()
  31.         ])
  32.     tac()
  33.  
  34. loop = asyncio.get_event_loop()
  35. loop.run_until_complete(main())
  36. loop.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement