ldo / inotipy Goto Github PK
View Code? Open in Web Editor NEWUse inotify(7) with asyncio in Python
Use inotify(7) with asyncio in Python
This project is no longer being maintained on GitHub. Look for it at one of * gitlab: https://gitlab.com/ldo/inotipy * bitbucket: https://bitbucket.org/ldo17/inotipy
During development, I need to watch certain files (not directories) that change and reload them. inotipy
does see the changes to these files but does not provide the name of the file that changed, which forces me to either watch the directories in which these files are and filter on the filename, or have one watcher per file. It would be more intuitive to have only one watcher for all these files and get the name of the file that indeed changed.
A basic example:
foo
and bar
in /tmp
:$ echo 1 > /tmp/foo
$ echo 2 > /tmp/bar
import sys
import asyncio
import inotify
async def mainline() :
watcher = inotify.Watcher.create()
for path in ('/tmp/foo','/tmp/bar'):
watcher.watch(path, inotify.IN.ALL_EVENTS)
while True :
event = await watcher.get()
sys.stdout.write("Got event: %s\n" % repr(event))
loop = asyncio.get_event_loop()
loop.run_until_complete(mainline())
$ echo 3 > /tmp/foo
$ echo 4 > /tmp/bar
Got event: Event(1, 0x00000002[<EVENT_BIT.MODIFY: 1>], 0, '')
Got event: Event(1, 0x00000020[<EVENT_BIT.OPEN: 5>], 0, '')
Got event: Event(1, 0x00000002[<EVENT_BIT.MODIFY: 1>], 0, '')
Got event: Event(1, 0x00000008[<EVENT_BIT.CLOSE_WRITE: 3>], 0, '')
Got event: Event(2, 0x00000002[<EVENT_BIT.MODIFY: 1>], 0, '')
Got event: Event(2, 0x00000020[<EVENT_BIT.OPEN: 5>], 0, '')
Got event: Event(2, 0x00000002[<EVENT_BIT.MODIFY: 1>], 0, '')
Got event: Event(2, 0x00000008[<EVENT_BIT.CLOSE_WRITE: 3>], 0, '')
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.