Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # copy-pasted from https://stackoverflow.com/a/63595496/1600898
- def iter_over_async(ait, loop):
- ait = ait.__aiter__()
- async def get_next():
- try:
- obj = await ait.__anext__()
- return False, obj
- except StopAsyncIteration:
- return True, None
- while True:
- done, obj = loop.run_until_complete(get_next())
- if done:
- break
- yield obj
- def folder_watchdog(path):
- loop = asyncio.get_event_loop()
- for item in iter_over_async(__watchdog(path), loop):
- print(item) # or other processing
Add Comment
Please, Sign In to add comment