当前位置: 首页>>代码示例>>Python>>正文


Python locks.Lock方法代码示例

本文整理汇总了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) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:18,代码来源:locks_test.py

示例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) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:19,代码来源:locks_test.py

示例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) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:18,代码来源:locks_test.py

示例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) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:18,代码来源:locks_test.py

示例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) 
开发者ID:openatx,项目名称:atxserver2-ios-provider,代码行数:21,代码来源:main.py

示例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 
开发者ID:openatx,项目名称:atxserver2-ios-provider,代码行数:21,代码来源:idb.py

示例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 
开发者ID:bdarnell,项目名称:tornado_http2,代码行数:19,代码来源:stream.py

示例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() 
开发者ID:Thriftpy,项目名称:thriftpy2,代码行数:18,代码来源:tornado.py

示例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) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:8,代码来源:locks_test.py

示例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()) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:9,代码来源:locks_test.py

示例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()) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:10,代码来源:locks_test.py

示例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 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:8,代码来源:locks_test.py

示例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 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:8,代码来源:locks_test.py

示例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) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:8,代码来源:locks_test.py

示例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()) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:9,代码来源:locks_test.py


注:本文中的tornado.locks.Lock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。