内容表

上一话题

QRandomGenerator64

下一话题

QReadWriteLock

QReadLocker

QReadLocker class is a convenience class that simplifies locking and unlocking read-write locks for read access. 更多

Inheritance diagram of PySide2.QtCore.QReadLocker

概要

函数

详细描述

The purpose of QReadLocker (and QWriteLocker ) is to simplify QReadWriteLock locking and unlocking. Locking and unlocking statements or in exception handling code is error-prone and difficult to debug. QReadLocker can be used in such situations to ensure that the state of the lock is always well-defined.

Here’s an example that uses QReadLocker to lock and unlock a read-write lock for reading:

lock = QReadWriteLock()
def readData():
    locker = QReadLocker(lock)
    # ...
    return data
											

它相当于以下代码:

lock = QReadWriteLock()
def readData():
    locker.lockForRead()
    # ...
    locker.unlock()
    return data
											

QMutexLocker 文档编制展示使用锁定器对象大大简化编程的范例。

class QReadLocker ( readWriteLock )
param readWriteLock

QReadWriteLock

构造 QReadLocker and locks lock for reading. The lock will be unlocked when the QReadLocker is destroyed. If lock is zero, QReadLocker does nothing.

另请参阅

lockForRead()

PySide2.QtCore.QReadLocker. __enter__ ( )
PySide2.QtCore.QReadLocker. __exit__ ( arg__1 , arg__2 , arg__3 )
参数
  • arg__1 PyObject

  • arg__2 PyObject

  • arg__3 PyObject

PySide2.QtCore.QReadLocker. readWriteLock ( )
返回类型

QReadWriteLock

返回指向被传递给构造函数的读写锁的指针。

PySide2.QtCore.QReadLocker. relock ( )

重新锁定被解锁的锁。

另请参阅

unlock()

PySide2.QtCore.QReadLocker. unlock ( )

解锁关联此锁定器的锁。

另请参阅

unlock()