• PySide 模块
  • PySide.QtCore
  • 内容表

    上一话题

    QSemaphore

    下一话题

    QReadLocker

    QWriteLocker

    概要

    函数

    详细描述

    PySide.QtCore.QWriteLocker class is a convenience class that simplifies locking and unlocking read-write locks for write access.

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

    Here's an example that uses PySide.QtCore.QWriteLocker to lock and unlock a read-write lock for writing:

    lock = QReadWriteLock()
    def writeData(data):
        locker = QWriteLocker(lock)
        # ...
    										

    它相当于以下代码:

    lock = QReadWriteLock()
    def writeData(data):
        locker.lockForWrite()
        # ...
        locker.unlock()
    										

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

    class PySide.QtCore. QWriteLocker ( readWriteLock )
    参数: readWriteLock PySide.QtCore.QReadWriteLock

    构造 PySide.QtCore.QWriteLocker and locks lock for writing. The lock will be unlocked when the PySide.QtCore.QWriteLocker is destroyed. If lock is zero, PySide.QtCore.QWriteLocker does nothing.

    PySide.QtCore.QWriteLocker. __enter__ ( )
    PySide.QtCore.QWriteLocker. __exit__ ( arg__1 , arg__2 , arg__3 )
    参数:
    • arg__1 PyObject
    • arg__2 PyObject
    • arg__3 PyObject
    PySide.QtCore.QWriteLocker. readWriteLock ( )
    返回类型: PySide.QtCore.QReadWriteLock

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

    PySide.QtCore.QWriteLocker. relock ( )

    重新锁定被解锁的锁。

    PySide.QtCore.QWriteLocker. unlock ( )

    解锁关联此锁定器的锁。