|
SU2
|
Public Member Functions | |
| def | __init__ (self, file_name, timeout=10, delay=.05) |
| def | acquire (self) |
| def | release (self) |
| def | __enter__ (self) |
| def | __exit__ (self, type, value, traceback) |
| def | __del__ (self) |
Public Attributes | |
| is_locked | |
| lockfile | |
| file_name | |
| timeout | |
| delay | |
| fd | |
A file locking mechanism that has context-manager support so
you can use it in a with statement.
Example:
with filelock("test.txt", timeout=2, delay=0.5):
print("Lock acquired.")
# Do something with the locked file
Inputs:
file_name - filename to lock
timeout - default 10sec, maximum timeout to wait for lock
delay - default 0.05sec, delay between each attempt to lock
number incremented with a random perturbation
original source: Evan Fosmark, BSD license
http://www.evanfosmark.com/2009/01/cross-platform-file-locking-support-in-python/
| def SU2.io.filelock.filelock.__init__ | ( | self, | |
| file_name, | |||
timeout = 10, |
|||
delay = .05 |
|||
| ) |
Prepare the file locker. Specify the file to lock and optionally
the maximum timeout and the delay between each attempt to lock.
| def SU2.io.filelock.filelock.__del__ | ( | self | ) |
Make sure that the FileLock instance doesn't leave a lockfile
lying around.
| def SU2.io.filelock.filelock.__enter__ | ( | self | ) |
Activated when used in the with statement.
Should automatically acquire a lock to be used in the with block.
| def SU2.io.filelock.filelock.__exit__ | ( | self, | |
| type, | |||
| value, | |||
| traceback | |||
| ) |
Activated at the end of the with statement.
It automatically releases the lock if it isn't locked.
| def SU2.io.filelock.filelock.acquire | ( | self | ) |
Acquire the lock, if possible. If the lock is in use, it check again
every `wait` seconds. It does this until it either gets the lock or
exceeds `timeout` number of seconds, in which case it throws
an exception.
| def SU2.io.filelock.filelock.release | ( | self | ) |
Get rid of the lock by deleting the lockfile.
When working in a `with` statement, this gets automatically
called at the end.
1.8.12