Guest User

Untitled

a guest
Oct 6th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. # copy-pasted from https://stackoverflow.com/a/63595496/1600898
  2. def iter_over_async(ait, loop):
  3.     ait = ait.__aiter__()
  4.     async def get_next():
  5.         try:
  6.             obj = await ait.__anext__()
  7.             return False, obj
  8.         except StopAsyncIteration:
  9.             return True, None
  10.     while True:
  11.         done, obj = loop.run_until_complete(get_next())
  12.         if done:
  13.             break
  14.         yield obj
  15.  
  16. def folder_watchdog(path):
  17.     loop = asyncio.get_event_loop()
  18.     for item in iter_over_async(__watchdog(path), loop):
  19.         print(item)  # or other processing
  20.  
Add Comment
Please, Sign In to add comment