PythonQt.QtCore.QLockFile · declarations 001
Back to PythonQt.QtCore.QLockFile
LockError
instance-attribute
LockError: type
int([x]) -> integer int(x, base=10) -> integer
Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.int(). For floating point numbers, this truncates towards zero.
If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by '+' or '-' and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal.
int('0b100', base=0) 4
LockFailedError
instance-attribute
LockFailedError: Any
PermissionError
instance-attribute
PermissionError: Any
UnknownError
instance-attribute
UnknownError: Any
error
error() -> Any
X.error()
Supplemental documentation: Qt 5 reference:
QLockFile::LockError QLockFile::error() const
Returns the lock file error status.
If tryLock() returns
false, this function can be called to find out the reason why the locking failed.
Upstream PySide2 reference signatures (binding differences may apply):
error(self) -> PySide2.QtCore.QLockFile.LockError
Source: https://doc.qt.io/archives/qt-5.15/qlockfile.html#error
getLockInfo
getLockInfo(pid: Any, hostname: Any, appname: Any) -> bool
X.getLockInfo(pid, hostname, appname) -> bool
Supplemental documentation: Qt 5 reference:
bool QLockFile::getLockInfo(qint64 *pid, QString *hostname, QString *appname) const
Retrieves information about the current owner of the lock file.
If tryLock() returns
false, and error() returns
LockFailedError,
this function can be called to find out more information about the existing lock file:
- the PID of the application (returned in pid)
- the hostname it's running on (useful in case of networked filesystems),
- the name of the application which created it (returned in appname),
Note that tryLock() automatically deleted the file if there is no running application with this PID, so LockFailedError can only happen if there is an application with this PID (it could be unrelated though).
This can be used to inform users about the existing lock file and give them the choice to delete it. After removing the file using removeStaleLockFile(), the application can call tryLock() again.
This function returns true if the information could be successfully retrieved, false
if the lock file doesn't exist or doesn't contain the expected data. This can happen if
the lock file was deleted between the time where
tryLock() failed and the
call to this function. Simply call
tryLock() again if this
happens.
Upstream PySide2 reference signatures (binding differences may apply):
getLockInfo(self) -> typing.Tuple[bool, int, str, str]
Source: https://doc.qt.io/archives/qt-5.15/qlockfile.html#getLockInfo
isLocked
isLocked() -> bool
X.isLocked() -> bool
Supplemental documentation: Qt 5 reference:
bool QLockFile::isLocked() const
Returns true if the lock was acquired by this
QLockFile instance, otherwise
returns false.
See also lock(), unlock(), and tryLock().
Upstream PySide2 reference signatures (binding differences may apply):
isLocked(self) -> bool
Source: https://doc.qt.io/archives/qt-5.15/qlockfile.html#isLocked
lock
lock() -> bool
X.lock() -> bool
Supplemental documentation: Qt 5 reference:
bool QLockFile::lock()
Creates the lock file.
If another process (or another thread) has created the lock file already, this function will block until that process (or thread) releases it.
Calling this function multiple times on the same lock from the same thread without unlocking first is not allowed. This function will dead-lock when the file is locked recursively.
Returns true if the lock was acquired, false if it could not be acquired due to an
unrecoverable error, such as no permissions in the parent directory.
See also unlock() and tryLock().
Upstream PySide2 reference signatures (binding differences may apply):
lock(self) -> bool
Source: https://doc.qt.io/archives/qt-5.15/qlockfile.html#lock
removeStaleLockFile
removeStaleLockFile() -> bool
X.removeStaleLockFile() -> bool
Supplemental documentation: Qt 5 reference:
bool QLockFile::removeStaleLockFile()
Attempts to forcefully remove an existing lock file.
Calling this is not recommended when protecting a short-lived operation: QLockFile already takes care of removing lock files after they are older than staleLockTime().
This method should only be called when protecting a resource for a long time, i.e. with staleLockTime(0), and after tryLock() returned LockFailedError, and the user agreed on removing the lock file.
Returns true on success, false if the lock file couldn't be removed. This happens on
Windows, when the application owning the lock is still running.
Upstream PySide2 reference signatures (binding differences may apply):
removeStaleLockFile(self) -> bool
Source: https://doc.qt.io/archives/qt-5.15/qlockfile.html#removeStaleLockFile
setStaleLockTime
setStaleLockTime(arg__1: int) -> None
X.setStaleLockTime(arg__1)
Supplemental documentation: Qt 5 reference:
void QLockFile::setStaleLockTime(int staleLockTime)
Sets staleLockTime to be the time in milliseconds after which a lock file is considered stale. The default value is 30000, i.e. 30 seconds. If your application typically keeps the file locked for more than 30 seconds (for instance while saving megabytes of data for 2 minutes), you should set a bigger value using setStaleLockTime().
The value of staleLockTime is used by lock() and tryLock() in order to determine when an existing lock file is considered stale, i.e. left over by a crashed process. This is useful for the case where the PID got reused meanwhile, so one way to detect a stale lock file is by the fact that it has been around for a long time.
See also staleLockTime().
Upstream PySide2 reference signatures (binding differences may apply):
setStaleLockTime(self, arg__1: int) -> None
Source: https://doc.qt.io/archives/qt-5.15/qlockfile.html#setStaleLockTime
staleLockTime
staleLockTime() -> int
X.staleLockTime() -> int
Supplemental documentation: Qt 5 reference:
int QLockFile::staleLockTime() const
Returns the time in milliseconds after which a lock file is considered stale.
See also setStaleLockTime().
Upstream PySide2 reference signatures (binding differences may apply):
staleLockTime(self) -> int
Source: https://doc.qt.io/archives/qt-5.15/qlockfile.html#staleLockTime
tryLock
tryLock(timeout: int) -> bool
X.tryLock(timeout) -> bool
Supplemental documentation: Qt 5 reference:
bool QLockFile::tryLock(int timeout \= 0)
Attempts to create the lock file. This function returns true if the lock was obtained;
otherwise it returns false. If another process (or another thread) has created the
lock file already, this function will wait for at most timeout milliseconds for the
lock file to become available.
Note: Passing a negative number as the timeout is equivalent to calling lock(), i.e. this function will wait forever until the lock file can be locked if timeout is negative.
If the lock was obtained, it must be released with unlock() before another process (or thread) can successfully lock it.
Calling this function multiple times on the same lock from the same thread without unlocking first is not allowed, this function will always return false when attempting to lock the file recursively.
Upstream PySide2 reference signatures (binding differences may apply):
tryLock(self, timeout: int=...) -> bool
Source: https://doc.qt.io/archives/qt-5.15/qlockfile.html#tryLock
unlock
unlock() -> None
X.unlock()
Supplemental documentation: Qt 5 reference:
void QLockFile::unlock()
Releases the lock, by deleting the lock file.
Calling unlock() without locking the file first, does nothing.
See also lock() and tryLock().
Upstream PySide2 reference signatures (binding differences may apply):
unlock(self) -> None
Source: https://doc.qt.io/archives/qt-5.15/qlockfile.html#unlock