Package plumbum.fs¶
File system utilities
Atomic file operations
- class plumbum.fs.atomic.AtomicCounterFile(atomicfile, initial=0)[source]¶
An atomic counter based on AtomicFile. Each time you call
next(), it will atomically read and increment the counter’s value, returning its previous valueExample:
acf = AtomicCounterFile.open("/some/file") print(acf.next()) # e.g., 7 print(acf.next()) # 8 print(acf.next()) # 9
Added in version 1.3.
- classmethod open(filename)[source]¶
Shortcut for
AtomicCounterFile(AtomicFile(filename))- Return type:
Self
- class plumbum.fs.atomic.AtomicFile(filename, ignore_deletion=False)[source]¶
Atomic file operations implemented using file-system advisory locks (
flockon POSIX,LockFileon Windows).Note
On Linux, the manpage says
flockmight have issues with NFS mounts. You should take this into account.Added in version 1.3.
- reopen()[source]¶
Close and reopen the file; useful when the file was deleted from the file system by a different process
- Return type:
- locked(blocking=True)[source]¶
A context manager that locks the file; this function is reentrant by the thread currently holding the lock.
Read the file without holding the lock
- Return type:
- class plumbum.fs.atomic.PidFile(filename)[source]¶
A PID file is a file that’s locked by some process from the moment it starts until it dies (the OS will clear the lock when the process exits). It is used to prevent two instances of the same process (normally a daemon) from running concurrently. The PID file holds its process’ PID, so you know who’s holding it.
Added in version 1.3.
- acquire()[source]¶
Attempt to acquire the PID file. If it’s already locked, raises
PidFileTaken. You should normally acquire the file as early as possible when the program starts- Return type:
- exception plumbum.fs.atomic.PidFileTaken(msg, pid)[source]¶
This exception is raised when PidFile.acquire fails to lock the pid file. Note that it derives from
SystemExit, so unless explicitly handled, it will terminate the process cleanly.
- class plumbum.fs.mounts.MountEntry(dev, point, fstype, options)[source]¶
Represents a mount entry (device file, mount point and file system type)
- plumbum.fs.mounts.mount_table()[source]¶
Returns the system’s current mount table (a list of
MountEntryobjects)- Return type: