Skip to content

Instantly share code, notes, and snippets.

@johnmaguire
Created January 30, 2023 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnmaguire/b5577159f6c5ea041898de9e3ed247af to your computer and use it in GitHub Desktop.
Save johnmaguire/b5577159f6c5ea041898de9e3ed247af to your computer and use it in GitHub Desktop.
inotify wrapper - Use inotify to watch for changes (saved from a 2019 repo)
FROM python:3
WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
ENTRYPOINT [ "python", "./main.py" ]
import argparse
import subprocess
from inotify_simple import INotify, flags
if __name__ == "__main__":
# Look for arguments
parser = argparse.ArgumentParser()
parser.add_argument('-d', dest='directory',
help='directory to watch for file changes')
parser.add_argument('-c', dest='command',
help='command to run when changes are detected')
args = parser.parse_args()
# Setup inotify
inotify = INotify()
watch_flags = flags.CREATE | flags.DELETE | flags.MODIFY | \
flags.DELETE_SELF
wd = inotify.add_watch(args.directory, watch_flags)
# Wait for inotify events
while True:
_ = inotify.read(read_delay=1000)
subprocess.call(args.command, shell=True)
inotify-simple==1.1.8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment