Skip to Content
Hands-On Reactive Programming with Python
book

Hands-On Reactive Programming with Python

by Romain Picard
October 2018
Intermediate to advanced
420 pages
10h 26m
English
Packt Publishing
Content preview from Hands-On Reactive Programming with Python

Monitoring file changes with inotify

Fortunately, there is already a Python package that exposes the inotify features with Asyncio—aionotify. This package is available on pypi and can be installed with pip (as usual from your virtualenv):

pip3 install aionotify

The aionotify API is simple to use (by the way, the original inotify API is already simple for a C API), and access to the events leverages coroutines and the await notation. See the following example:

import asyncioimport aionotify# Setup the watcherwatcher = aionotify.Watcher()watcher.watch(alias='test', path='/tmp/foo.txt', flags=    aionotify.Flags.OPEN     | aionotify.Flags.CLOSE_WRITE     | aionotify.Flags.ACCESS     | aionotify.Flags.MODIFY)# Prepare the looploop = asyncio.get_event_loop() ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python Programming with Design Patterns

Python Programming with Design Patterns

James W. Cooper

Publisher Resources

ISBN: 9781789138726Supplemental Content