oauth2client.locked_file module¶
Locked file interface that should work on Unix and Windows pythons.
This module first tries to use fcntl locking to ensure serialized access to a file, then falls back on a lock file if that is unavialable.
Usage:
f = LockedFile('filename', 'r+b', 'rb')
f.open_and_lock()
if f.is_locked():
print('Acquired filename with r+b mode')
f.file_handle().write('locked data')
else:
print('Acquired filename with rb mode')
f.unlock_and_close()
-
exception
oauth2client.locked_file.
AlreadyLockedException
[source]¶ Bases:
exceptions.Exception
Trying to lock a file that has already been locked by the LockedFile.
-
exception
oauth2client.locked_file.
CredentialsFileSymbolicLinkError
[source]¶ Bases:
exceptions.Exception
Credentials files must not be symbolic links.
-
class
oauth2client.locked_file.
LockedFile
(*args, **kwargs)[source]¶ Bases:
object
Represent a file that has exclusive access.
-
open_and_lock
(timeout=0, delay=0.05)[source]¶ Open the file, trying to lock it.
Parameters: - timeout – float, The number of seconds to try to acquire the lock.
- delay – float, The number of seconds to wait between retry attempts.
Raises: AlreadyLockedException
– if the lock is already acquired.IOError
– if the open fails.
-