本文整理匯總了Python中tornado.locks.Lock方法的典型用法代碼示例。如果您正苦於以下問題:Python locks.Lock方法的具體用法?Python locks.Lock怎麽用?Python locks.Lock使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tornado.locks
的用法示例。
在下文中一共展示了locks.Lock方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_acquire_fifo
# 需要導入模塊: from tornado import locks [as 別名]
# 或者: from tornado.locks import Lock [as 別名]
def test_acquire_fifo(self):
lock = locks.Lock()
self.assertTrue(lock.acquire().done())
N = 5
history = []
@gen.coroutine
def f(idx):
with (yield lock.acquire()):
history.append(idx)
futures = [f(i) for i in range(N)]
self.assertFalse(any(future.done() for future in futures))
lock.release()
yield futures
self.assertEqual(list(range(N)), history)
示例2: test_acquire_fifo_async_with
# 需要導入模塊: from tornado import locks [as 別名]
# 或者: from tornado.locks import Lock [as 別名]
def test_acquire_fifo_async_with(self):
# Repeat the above test using `async with lock:`
# instead of `with (yield lock.acquire()):`.
lock = locks.Lock()
self.assertTrue(lock.acquire().done())
N = 5
history = []
namespace = exec_test(globals(), locals(), """
async def f(idx):
async with lock:
history.append(idx)
""")
futures = [namespace['f'](i) for i in range(N)]
lock.release()
yield futures
self.assertEqual(list(range(N)), history)
示例3: test_acquire_fifo
# 需要導入模塊: from tornado import locks [as 別名]
# 或者: from tornado.locks import Lock [as 別名]
def test_acquire_fifo(self):
lock = locks.Lock()
self.assertTrue(asyncio.ensure_future(lock.acquire()).done())
N = 5
history = []
@gen.coroutine
def f(idx):
with (yield lock.acquire()):
history.append(idx)
futures = [f(i) for i in range(N)]
self.assertFalse(any(future.done() for future in futures))
lock.release()
yield futures
self.assertEqual(list(range(N)), history)
示例4: test_acquire_fifo_async_with
# 需要導入模塊: from tornado import locks [as 別名]
# 或者: from tornado.locks import Lock [as 別名]
def test_acquire_fifo_async_with(self):
# Repeat the above test using `async with lock:`
# instead of `with (yield lock.acquire()):`.
lock = locks.Lock()
self.assertTrue(asyncio.ensure_future(lock.acquire()).done())
N = 5
history = []
async def f(idx):
async with lock:
history.append(idx)
futures = [f(i) for i in range(N)]
lock.release()
yield futures
self.assertEqual(list(range(N)), history)
示例5: device_watch
# 需要導入模塊: from tornado import locks [as 別名]
# 或者: from tornado.locks import Lock [as 別名]
def device_watch(wda_directory: str):
"""
When iOS device plugin, launch WDA
"""
lock = locks.Lock() # WDA launch one by one
async for event in idb.track_devices():
if event.udid.startswith("ffffffffffffffffff"):
logger.debug("Invalid event: %s", event)
continue
logger.debug("Event: %s", event)
if event.present:
d = idb.WDADevice(event.udid, lock=lock, callback=_device_callback)
d.wda_directory = wda_directory
idevices[event.udid] = d
d.start()
else: # offline
await idevices[event.udid].stop()
idevices.pop(event.udid)
示例6: __init__
# 需要導入模塊: from tornado import locks [as 別名]
# 或者: from tornado.locks import Lock [as 別名]
def __init__(self, udid: str, lock: locks.Lock, callback):
"""
Args:
callback: function (str, dict) -> None
Example callback:
callback("update", {"ip": "1.2.3.4"})
"""
self.__udid = udid
self.name = udid2name(udid)
self.product = udid2product(udid)
self.wda_directory = "./ATX-WebDriverAgent"
self._procs = []
self._wda_proxy_port = None
self._wda_proxy_proc = None
self._lock = lock # only allow one xcodebuild test run
self._finished = locks.Event()
self._stop = locks.Event()
self._callback = partial(callback, self) or nop_callback
示例7: __init__
# 需要導入模塊: from tornado import locks [as 別名]
# 或者: from tornado.locks import Lock [as 別名]
def __init__(self, conn, stream_id, delegate, context=None):
self.conn = conn
self.stream_id = stream_id
self.set_delegate(delegate)
self.context = context
self.finish_future = Future()
self.write_lock = Lock()
from tornado.util import ObjectDict
# TODO: remove
self.stream = ObjectDict(io_loop=IOLoop.current(), close=conn.stream.close)
self._incoming_content_remaining = None
self._outgoing_content_remaining = None
self._delegate_started = False
self.window = Window(conn.window, stream_id,
conn.setting(constants.Setting.INITIAL_WINDOW_SIZE))
self._header_frames = []
self._phase = constants.HTTPPhase.HEADERS
示例8: __init__
# 需要導入模塊: from tornado import locks [as 別名]
# 或者: from tornado.locks import Lock [as 別名]
def __init__(self, host, port, stream=None, io_loop=None, ssl_options=None,
read_timeout=DEFAULT_READ_TIMEOUT):
self.host = host
self.port = port
self.io_loop = io_loop
self.read_timeout = read_timeout
self.is_queuing_reads = False
self.read_queue = []
self.__wbuf = BytesIO()
self._read_lock = Lock()
self.ssl_options = ssl_options
# servers provide a ready-to-go stream
self.stream = stream
if self.stream is not None:
self._set_close_callback()
示例9: test_repr
# 需要導入模塊: from tornado import locks [as 別名]
# 或者: from tornado.locks import Lock [as 別名]
def test_repr(self):
lock = locks.Lock()
# No errors.
repr(lock)
lock.acquire()
repr(lock)
示例10: test_acquire_release
# 需要導入模塊: from tornado import locks [as 別名]
# 或者: from tornado.locks import Lock [as 別名]
def test_acquire_release(self):
lock = locks.Lock()
self.assertTrue(lock.acquire().done())
future = lock.acquire()
self.assertFalse(future.done())
lock.release()
self.assertTrue(future.done())
示例11: test_acquire_timeout
# 需要導入模塊: from tornado import locks [as 別名]
# 或者: from tornado.locks import Lock [as 別名]
def test_acquire_timeout(self):
lock = locks.Lock()
lock.acquire()
with self.assertRaises(gen.TimeoutError):
yield lock.acquire(timeout=timedelta(seconds=0.01))
# Still locked.
self.assertFalse(lock.acquire().done())
示例12: test_yield_lock
# 需要導入模塊: from tornado import locks [as 別名]
# 或者: from tornado.locks import Lock [as 別名]
def test_yield_lock(self):
# Ensure we catch a "with (yield lock)", which should be
# "with (yield lock.acquire())".
with self.assertRaises(gen.BadYieldError):
with (yield locks.Lock()):
pass
示例13: test_context_manager_misuse
# 需要導入模塊: from tornado import locks [as 別名]
# 或者: from tornado.locks import Lock [as 別名]
def test_context_manager_misuse(self):
# Ensure we catch a "with lock", which should be
# "with (yield lock.acquire())".
with self.assertRaises(RuntimeError):
with locks.Lock():
pass
示例14: test_multi_release
# 需要導入模塊: from tornado import locks [as 別名]
# 或者: from tornado.locks import Lock [as 別名]
def test_multi_release(self):
lock = locks.Lock()
self.assertRaises(RuntimeError, lock.release)
lock.acquire()
lock.release()
self.assertRaises(RuntimeError, lock.release)
示例15: test_acquire_release
# 需要導入模塊: from tornado import locks [as 別名]
# 或者: from tornado.locks import Lock [as 別名]
def test_acquire_release(self):
lock = locks.Lock()
self.assertTrue(asyncio.ensure_future(lock.acquire()).done())
future = asyncio.ensure_future(lock.acquire())
self.assertFalse(future.done())
lock.release()
self.assertTrue(future.done())