本文整理汇总了Python中gevent.lock.RLock方法的典型用法代码示例。如果您正苦于以下问题:Python lock.RLock方法的具体用法?Python lock.RLock怎么用?Python lock.RLock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gevent.lock
的用法示例。
在下文中一共展示了lock.RLock方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __module_lock
# 需要导入模块: from gevent import lock [as 别名]
# 或者: from gevent.lock import RLock [as 别名]
def __module_lock(name):
# Return the lock for the given module, creating it if necessary.
# It will be removed when no longer needed.
# Nothing in this function yields, so we're multi-greenlet safe
# (But not multi-threading safe.)
# XXX: What about on PyPy, where the GC is asynchronous (not ref-counting)?
# (Does it stop-the-world first?)
lock = None
try:
lock = _g_import_locks[name]()
except KeyError:
pass
if lock is None:
lock = RLock()
def cb(_):
# We've seen a KeyError on PyPy on RPi2
_g_import_locks.pop(name, None)
_g_import_locks[name] = weakref.ref(lock, cb)
return lock
示例2: __init__
# 需要导入模块: from gevent import lock [as 别名]
# 或者: from gevent.lock import RLock [as 别名]
def __init__(self, url, recv_msg_cbk=None, close_cbk=None, protocols=None, msg_encoder=None, msg_decoder=None):
# patch socket.sendall to protect it with lock,
# in order to prevent sending data from multiple greenlets concurrently
WebSocketClient.__init__(self, url, protocols=protocols)
self._msg_encoder = msg_encoder or self.DEFAULT_ENCODER
self._msg_decoder = msg_decoder or self.DEFAULT_DECODER
lock = RLock()
_sendall = self.sock.sendall
self._recv_msg_cbk = recv_msg_cbk
self._close_cbk = close_cbk
def sendall(data):
lock.acquire()
try:
_sendall(data)
except Exception:
raise
finally:
lock.release()
self.sock.sendall = sendall
self.connect()
log.info('Created {0}'.format(self))
示例3: client
# 需要导入模块: from gevent import lock [as 别名]
# 或者: from gevent.lock import RLock [as 别名]
def client(connect, *, writable=False, dovecot=False, debug=None):
def start():
con = connect()
con.debug = conf['DEBUG_IMAP'] if debug is None else debug
con.lock = RLock()
con.new = new
return con
def new():
c = start()
if con.current_box:
c.select(con.current_box, con.is_readonly)
return c
connect = fn_time(connect, '{0.__module__}.{0.__name__}'.format(connect))
con = start()
ctx = Ctx(con)
for cmd, opts in commands.items():
if not dovecot and opts['dovecot']:
continue
elif not writable and opts['writable']:
continue
setattr(ctx, cmd.name, ft.partial(cmd, con))
return ctx
示例4: get_lock
# 需要导入模块: from gevent import lock [as 别名]
# 或者: from gevent.lock import RLock [as 别名]
def get_lock(self, lock_name):
from gevent.lock import RLock
lock_name = _normalize_path(lock_name)
if lock_name not in self._store:
lock = RLock()
self.write(lock_name, lock)
else:
lock = self._store[lock_name]
return lock
示例5: __new__
# 需要导入模块: from gevent import lock [as 别名]
# 或者: from gevent.lock import RLock [as 别名]
def __new__(cls, *args, **kw):
if args or kw:
if (PYPY and cls.__init__ == object.__init__) or (not PYPY and cls.__init__ is object.__init__):
raise TypeError("Initialization arguments are not supported")
self = object.__new__(cls)
impl = _localimpl()
impl.localargs = (args, kw)
impl.locallock = RLock()
object.__setattr__(self, '_local__impl', impl)
# We need to create the thread dict in anticipation of
# __init__ being called, to make sure we don't call it
# again ourselves.
impl.create_dict()
return self
示例6: __init__
# 需要导入模块: from gevent import lock [as 别名]
# 或者: from gevent.lock import RLock [as 别名]
def __init__(self, conf):
super(WechatQYBackend, self).__init__(conf)
self.lock = RLock()
self.token_cache = {}
示例7: __init__
# 需要导入模块: from gevent import lock [as 别名]
# 或者: from gevent.lock import RLock [as 别名]
def __init__(self):
self.alarms = {}
self.lock = RLock()
示例8: opened
# 需要导入模块: from gevent import lock [as 别名]
# 或者: from gevent.lock import RLock [as 别名]
def opened(self):
# patch socket.sendall to protect it with lock,
# in order to prevent sending data from multiple greenlets concurrently
lock = RLock()
_sendall = self.sock.sendall
def sendall(data):
lock.acquire()
try:
_sendall(data)
except Exception:
raise
finally:
lock.release()
self.sock.sendall = sendall
# start check idle
if self._pingpong_trigger:
self._last_active_ts = get_monotonic_time()
self._pingpong_check_greenlet = gevent.spawn(self._pingpong_check_routine)
# create app
try:
if not self.environ.get('QUERY_STRING'):
query = {}
else:
query = urllib.parse.parse_qs(self.environ['QUERY_STRING'], keep_blank_values=True)
for key, value in query.items():
query[key] = value[0]
self._recv_msg_cbk = self.environ['app.recv_msg_cbk']
self._closed_cbk = self.environ['app.closed_cbk']
log.info('Created {0}'.format(self))
except Exception:
log.exception('Failed to create app for {0}'.format(self))
raise
示例9: __init__
# 需要导入模块: from gevent import lock [as 别名]
# 或者: from gevent.lock import RLock [as 别名]
def __init__(self,
inactivity_timeout=10, # minutes
sweep_time=1, # minute
attach_timeout=60, # seconds
timeout_disable_mode='soft'):
"""
inactivity_timeout is the amount of time in minutes that a session may
go without any messages being sent before it is killed. If
inactivity_timeout is None, then sessions may sit innactive forever.
sweep_time is the amount of time in minutes between checks to kill
inactive sessions.
attach_timeout is the amount of time in secondsto wait for both sides
of a session to attach before killing one off. If attach_timeout is
None, then it will wait forever. If attach_timeout is 0, then it will
allow for orphaned sessions, meaning a clients with no tracer, or a
tracer with no clients. These may be attached later.
timeout_disable_mode is the mode to kill the sessions with in the event
of a timeout. This mode may be 'hard' or 'soft'.
"""
if timeout_disable_mode not in ['soft', 'hard']:
raise ValueError("timeout_disable_mode must be 'hard' or 'soft'")
self.inactivity_timeout = inactivity_timeout
self.sweep_time = sweep_time
self.attach_timeout = attach_timeout
self.timeout_disable_mode = timeout_disable_mode
self._sessions = {}
self.gc_glet = None
self._lock = RLock()
示例10: __init__
# 需要导入模块: from gevent import lock [as 别名]
# 或者: from gevent.lock import RLock [as 别名]
def __init__(self, next_sink):
super(RefCountedSink, self).__init__()
self._ref_count = 0
self._open_lock = RLock()
self._open_ar = None
self.next_sink = next_sink
示例11: __init__
# 需要导入模块: from gevent import lock [as 别名]
# 或者: from gevent.lock import RLock [as 别名]
def __init__(self):
self.channels = {}
self.connections = {}
self.users = {}
self.stats = {"total_messages": 0, "total_unique_messages": 0}
self.lock = RLock()
示例12: __init__
# 需要导入模块: from gevent import lock [as 别名]
# 或者: from gevent.lock import RLock [as 别名]
def __init__(self,
mesos_master_path,
zk_servers,
**kwargs):
self._members = {}
self._current_leader = None
self._member_lock = RLock()
self._zk_server_set = None
self._next_on_join = self._on_join(mesos_master_path)
self._next_on_leave = self._on_leave(mesos_master_path)
super(MesosMasterProxySource, self).__init__(mesos_master_path, zk_servers, **kwargs)
示例13: _create_lock
# 需要导入模块: from gevent import lock [as 别名]
# 或者: from gevent.lock import RLock [as 别名]
def _create_lock(self):
return RLock()
示例14: test_concurrent_updates
# 需要导入模块: from gevent import lock [as 别名]
# 或者: from gevent.lock import RLock [as 别名]
def test_concurrent_updates(self, dataengine):
store = dataengine.create_store("queue")
lock = RLock()
def task1():
print("Task1: start")
with lock:
with dataengine.cursor("queue", readonly=False) as cur:
cur.put('k1', 'value3')
print("Task1: k1 written.")
gevent.sleep(0)
cur.put('k2', 'value1')
print("Task1: k2 written.")
gevent.sleep(0)
cur.put('k3', 'value2')
print("Task1: k3 written.")
def task2():
print("Task2: start")
with lock:
with dataengine.cursor("queue", readonly=False) as cur2:
cur2.put('k4', 'value3')
print("Task2: k4 writen.")
gevent.sleep(0)
cur2.put('k5', 'value1')
print("Task2: k5 written.")
gevent.sleep(0)
cur2.put('k6', 'value2')
print("Task2: k6 written.")
def task3():
print("Task3: start")
with dataengine.cursor("queue", readonly=True) as cur3:
cur3.get('k1')
print("Task3: k1 read.")
gevent.sleep(0)
cur3.get('k2')
print("Task3: k2 read.")
gevent.sleep(0)
cur3.get('k3')
print("Task3: k3 read.")
t1 = gevent.spawn(task1)
t2 = gevent.spawn(task2)
t3 = gevent.spawn(task3)
gevent.joinall([t1, t2, t3])