Skip to main content

1 Summary

pollinotify is a simple extension module that wraps the Linux inotify service, providing a way to watch for specific kinds of file events happening to specified files or in specified directories. Its major selling points are that:

1 It is polled, so instead of having to set up a background thread, or attach a separate event-watching package, the programmer calls it with an optional timeout, so it reports event that have already occurred, or waits for at most the specified time, or until an event occurs;

2 The polling can wait for specific kinds of event.

As the module depends on the inotify service, it is only available on Linux.

2 Module Structure

2.1 Constants

A number of constants representing common Linux file system event codes, with friendly names:

Constant Name

Linux Name

Interpretation

Access

IN_ACCESS

Object accessed

Modify

IN_MODIFY

Object modified

Attributes

IN_ATTRIB

Object attributes modified

Open

IN_OPEN

File opened

CloseWrite

IN_CLOSE_WRITE

File closed after contents changed

CloseOther

IN_CLOSE_NOWRITE

File closed without contents changed

Close

IN_CLOSE

File closed

MoveFrom

IN_MOVED_FROM

Object moved from location

MoveTo

IN_MOVED_TO

Object moved to location

Move

IN_MOVE

Object moved

MoveSelf

IN_MOVE_SELF

Object being monitored is deleted

Create

IN_CREATE

Object created

Delete

IN_DELETE

Object deleted

DeleteSelf

IN_DELETE_SELF

Object being monitored is deleted

Ignored

IN_IGNORED

Ignored

DirEvent

IN_ISDIR

The monitored object to which the event occurred is a directory

AllEvents

IN_ALL_EVENTS

Any event

2.2 Utility functions

maskAsString(mask)

Takes a value equal to one or more of the event constants or-ed together and returns a readable string representation, consisting of a space-separated list of the names of the matching events

2.3 FileEvent class

FileEvent represents an event detected by the inotify service. The event information is held in the attributes:

self.path

The path to the file or directory suffering the event

self.mask

Value representing the event(s) it suffered, represented as an or-ed collection of event codes, one for each kind of event that was detected

self.decode()

Returns a list of the names of the event types to which the event corresponds

self.matches(mask)

Returns True if the argument is the code for one of the event types that the object represents, False otherwise

In addition, if e is a FileEvent object then

str(e) = maskAsString(e.mask)
len(e) = len(e.decode())
x in e = e.matches(x)

2.4 Watcher class

The fundamental class of the module. It connects to the system inotify service and uses it to poll for events in one or more specified file system paths. Polling is based on a timeout, and so can be non-blocking.

It has the following methods:

__init__()

No-args constructor

addPath(path,mode=AllEvents)

Adds path to the list of directories to be polled for events; polling will collect only events that match the or-ed event code mask specified in the optional argument mode (defaults to all events)

poll(timeout=0)

Polls for events occurring on the specified paths, returning True if any occur, False otherwise; times out after timeout milliseconds, in which case it returns False

events(match=AllEvents)

Returns a list of FileEvent objects, one for each event detected during last polling session that matches the specified optional or-ed event code mask

nPaths()

Returns the number of paths currently registered with the Watcher

nEvents()

Returns the number of events detected in the last polling session

If w is a Watcher instance then

len(w)  = w.nEvents()
iter(w) = iter(w.events())

3 EXAMPLE

A simple example that polls with a timeout of 1 second and lists those events corresponding to file creation or modification (including touch) in the user’s home directory.

import pollinotify

n=pollinotify.Watcher()
n.addPath('~')
while True:
    got=n.poll(timeout=1000)
    if got:
        events=n.events(match=notify.CloseWrite)
        print('Got{} events'.format(len(events))
        for event in events:
            print('{} : {} : {}'.format(event.path,event.mask,str(event)))

Metadata

Release files for pollinotify 1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pollinotify 1.2
File Size Uploaded Provenance
pollinotify-1.2.tar.gz 13.9 kB Without provenance Details

Release files / pollinotify-1.2.tar.gz

Download URL pollinotify-1.2.tar.gz
Size 13.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e89ee19f32e74c1c0a0c49ee2aa148e29af85c35ce4df0dcd5253d4a23295a76
BLAKE2b-256 checksum
How to use checksums
292372f42f32ff3865d6e7a45a17c93964acdd80d847b90ade5276b63f4d7b69
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for pollinotify 1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.2 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page