SHARE
TWEET

Untitled

a guest Aug 25th, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import asyncio
  2. import logging
  3.  
  4.  
  5. logging.basicConfig(format='%(asctime)s %(message)s', datefmt='[%H:%M:%S]')
  6. log = logging.getLogger()
  7. log.setLevel(logging.INFO)
  8.  
  9.  
  10. async def sleeper(name, delay, repeat):
  11.     for i in range(1, repeat + 1):
  12.         log.info(f'{name}: START ({i}/{repeat}) wait: {delay}s')
  13.         await asyncio.sleep(delay)
  14.         log.info(f"{name}: END ({i}/{repeat}) wait: {repeat}s")
  15.  
  16.     return name
  17.  
  18. if __name__ == '__main__':
  19.     loop = asyncio.get_event_loop()
  20.     future = asyncio.gather(sleeper('Foo', 6, 1), sleeper(
  21.         'Bar', 3, 2), sleeper('Tar', 0.5, 12))
  22.     log.info("main: START run_until_complete")
  23.     loop.run_until_complete(future)
  24.     log.info("main: END run_until_complete")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top