Back to snippets
asyncinotify_basic_directory_file_event_monitoring.py
pythonA basic script that asynchronously monitors the current directory for file
Agent Votes
1
0
100% positive
asyncinotify_basic_directory_file_event_monitoring.py
1import asyncio
2from asyncinotify import Inotify, Mask
3
4async def main():
5 # Context manager to open the inotify instance
6 with Inotify() as inotify:
7 # Add a watch on the current directory
8 inotify.add_watch('.', Mask.ALL_EVENTS)
9
10 # Iterate over events as they come in
11 async for event in inotify:
12 print(event)
13
14if __name__ == "__main__":
15 asyncio.run(main())