本文整理匯總了Python中threading._RLock方法的典型用法代碼示例。如果您正苦於以下問題:Python threading._RLock方法的具體用法?Python threading._RLock怎麽用?Python threading._RLock使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類threading
的用法示例。
在下文中一共展示了threading._RLock方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: init
# 需要導入模塊: import threading [as 別名]
# 或者: from threading import _RLock [as 別名]
def init(with_threads=1):
"""Initialize threading.
Don't bother calling this. If it needs to happen, it will happen.
"""
global threaded, _synchLockCreator, XLock
if with_threads:
if not threaded:
if threadingmodule is not None:
threaded = True
class XLock(threadingmodule._RLock, object):
def __reduce__(self):
return (unpickle_lock, ())
_synchLockCreator = XLock()
else:
raise RuntimeError("Cannot initialize threading, platform lacks thread support")
else:
if threaded:
raise RuntimeError("Cannot uninitialize threads")
else:
pass
示例2: init
# 需要導入模塊: import threading [as 別名]
# 或者: from threading import _RLock [as 別名]
def init(with_threads=1):
"""Initialize threading.
Don't bother calling this. If it needs to happen, it will happen.
"""
global threaded, _synchLockCreator, XLock
if with_threads:
if not threaded:
if threadmodule is not None:
threaded = True
class XLock(threadingmodule._RLock, object):
def __reduce__(self):
return (unpickle_lock, ())
_synchLockCreator = XLock()
else:
raise RuntimeError("Cannot initialize threading, platform lacks thread support")
else:
if threaded:
raise RuntimeError("Cannot uninitialize threads")
else:
pass
示例3: __init__
# 需要導入模塊: import threading [as 別名]
# 或者: from threading import _RLock [as 別名]
def __init__(self, *args):
from OpenSSL import SSL as _ssl
self._ssl_conn = apply(_ssl.Connection, args)
from threading import _RLock
self._lock = _RLock()
示例4: test_needs_underscored_versions
# 需要導入模塊: import threading [as 別名]
# 或者: from threading import _RLock [as 別名]
def test_needs_underscored_versions(self):
self.assertEqual(threading.Lock, threading._Lock)
self.assertEqual(threading.RLock, threading._RLock)
示例5: getRst
# 需要導入模塊: import threading [as 別名]
# 或者: from threading import _RLock [as 別名]
def getRst( self ):
"""
Get data necessary for a restart of the running calculation.
Locks, file handles and private data are *NOT* saved.
Override if necessary but call this method in child method.
@return: {..}, dict with 'pickleable' fields of master
@rtype: dict
"""
self.status.lock.acquire()
## collect master parameters that can be pickled
rst = {}
for k,v in self.__dict__.items():
skip = 0
for t in [ Thread, _RLock, _Condition, Status, file ]:
if isinstance( v, t ):
skip = 1
if str(k)[0] == '_':
skip = 1
if not skip:
rst[k] = copy.copy( v )
rst['status_objects'] = copy.deepcopy( self.status.objects )
rst['master_class'] = self.__class__
self.status.lock.release()
return rst
示例6: _safe_lock_release_py2
# 需要導入模塊: import threading [as 別名]
# 或者: from threading import _RLock [as 別名]
def _safe_lock_release_py2(rlock):
"""Ensure that a threading.RLock is fully released for Python 2.
The RLock release code is:
https://github.com/python/cpython/blob/2.7/Lib/threading.py#L187
The RLock object's release method does not release all of its state if an
exception is raised in the middle of its operation. There are three pieces of
internal state that must be cleaned up:
- owning thread ident, an integer.
- entry count, an integer that counts how many times the current owner has
locked the RLock.
- internal lock, a threading.Lock instance that handles blocking.
Args:
rlock: threading.RLock, lock to fully release.
Yields:
None.
"""
assert isinstance(rlock, threading._RLock)
ident = _thread.get_ident()
expected_count = 0
if rlock._RLock__owner == ident:
expected_count = rlock._RLock__count
try:
yield
except ThreadTerminationError:
# Check if the current thread still owns the lock by checking if we can
# acquire the underlying lock.
if rlock._RLock__block.acquire(0):
# Lock is clean, so unlock and we are done.
rlock._RLock__block.release()
elif rlock._RLock__owner == ident and expected_count > 0:
# The lock is still held up the stack, so make sure the count is accurate.
if rlock._RLock__count != expected_count:
rlock._RLock__count = expected_count
elif rlock._RLock__owner == ident or rlock._RLock__owner is None:
# The internal lock is still acquired, but either this thread or no thread
# owns it, which means it needs to be hard reset.
rlock._RLock__owner = None
rlock._RLock__count = 0
rlock._RLock__block.release()
raise
# pylint: enable=protected-access