Advertisement
Guest User

Untitled

a guest
Jul 16th, 2016
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. import asyncio
  2.  
  3. loop = asyncio.get_event_loop()
  4.  
  5.  
  6. class Some:
  7.  
  8.     def __init__(self):
  9.         self.cache = []
  10.         self.i = 0
  11.  
  12.     async def chota_run(self):
  13.         while True:
  14.             await asyncio.sleep(1)
  15.             self.i += 1
  16.             print('add to cache {}'.format(self.i))
  17.             self.cache.append(self.i)
  18.             print('cache: {}'.format(self.cache))
  19.  
  20.     async def clear_cache(self):
  21.         while True:
  22.             await asyncio.sleep(5)
  23.             print('!!! clear cache !!!')
  24.             self.cache = []
  25.  
  26. if __name__ == '__main__':
  27.     some = Some()
  28.     loop.create_task(some.chota_run())
  29.     loop.create_task(some.clear_cache())
  30.     loop.run_forever()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement