Stat — Stat watcher

class pyev.Stat(path, interval, loop, callback[, data=None, priority=0])
Parameters:
  • path – wait for status changes of the given path.
  • interval (float) – hint on how quickly a change is expected to be detected and should normally be specified as 0.0 to let libev choose a suitable value.
  • loop (Loop) – loop object responsible for this watcher (accessible through Watcher.loop).
  • callback (callable) – See Watcher.callback.
  • data (object) – any Python object you might want to attach to the watcher (stored in Watcher.data).
  • priority (int) – See Watcher.priority.

This watches a file system path for attribute changes. That is, it calls stat() on that path in regular intervals (or when the OS says it changed) and sees if it changed compared to the last time, invoking the callback if it did.

The path does not need to exist: changing from ‘path exists’ to ‘path does not exist’ is a status change like any other. The condition ‘path does not exist’ (or more correctly ‘path cannot be stat()ed’) is signified by the Statdata.nlink field being 0 (which is otherwise always forced to be at least 1) and all the other fields of the Statdata object having unspecified contents.

The path must not end in a slash or contain special components such as . or ... The path should be absolute: if it is relative and your working directory changes, then the behaviour is undefined.

Since there is no portable change notification interface available, the portable implementation simply calls stat() regularly on the path to see if it changed somehow. You can specify a recommended polling interval for this case. If you specify a polling interval of 0.0 (highly recommended!) then a suitable, unspecified default value will be used (which you can expect to be around five seconds, although this might change dynamically). libev will also impose a minimum interval which is currently around 0.1, but that’s usually overkill.

This watcher type is not meant for massive numbers of Stat watchers, as even with OS-supported change notifications, this can be resource-intensive.

set(path, interval)
Parameters:
  • path – wait for status changes of the given path.
  • interval (float) – hint on how quickly a change is expected to be detected and should normally be specified as 0.0 to let libev choose a suitable value.

Configures the watcher.

stat()

Updates Stat.current immediately with a new Statdata object. If you change the watched path in your callback, you could call this function to avoid detecting this change (while introducing a race condition if you are not the only one changing the path). Can also be useful simply to find out the new values.

path

Read only

The file system path that is being watched.

interval

Read only

The specified interval.

current

Read only

Current Statdata. If the nlink attribute is 0, then there was some error while stating the file.

previous

Read only

Previous Statdata. The callback gets invoked whenever Stat.previous != Stat.current, or, more precisely, one or more of these attributes differ: dev, ino, mode, nlink, uid, gid, rdev, size, atime, mtime, ctime.

Statdata

class pyev.Statdata
dev

Read only

device.

rdev

Read only

device type.

ino

Read only

inode.

size

Read only

total size, in bytes.

Read only

number of hard links.

mode

Read only

protection bits.

uid

Read only

user ID of owner.

gid

Read only

group ID of owner.

atime

Read only

time of last access.

mtime

Read only

time of last modification.

ctime

Read only

time of last status change.

Table Of Contents

Previous topic

Child — Child watcher

Next topic

Idle — Idle watcher

This Page