Python tornado.locks.Lock() Examples
The following are 30
code examples of tornado.locks.Lock().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
tornado.locks
, or try the search function
.
Example #1
Source File: locks_test.py From opendevops with GNU General Public License v3.0 | 6 votes |
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)
Example #2
Source File: locks_test.py From pySINDy with MIT License | 6 votes |
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)
Example #3
Source File: locks_test.py From pySINDy with MIT License | 6 votes |
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)
Example #4
Source File: main.py From atxserver2-ios-provider with MIT License | 6 votes |
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)
Example #5
Source File: idb.py From atxserver2-ios-provider with MIT License | 6 votes |
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
Example #6
Source File: stream.py From tornado_http2 with Apache License 2.0 | 6 votes |
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
Example #7
Source File: locks_test.py From teleport with Apache License 2.0 | 6 votes |
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)
Example #8
Source File: locks_test.py From teleport with Apache License 2.0 | 6 votes |
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)
Example #9
Source File: locks_test.py From EventGhost with GNU General Public License v2.0 | 6 votes |
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)
Example #10
Source File: locks_test.py From opendevops with GNU General Public License v3.0 | 6 votes |
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)
Example #11
Source File: locks_test.py From EventGhost with GNU General Public License v2.0 | 6 votes |
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)
Example #12
Source File: tornado.py From thriftpy2 with MIT License | 6 votes |
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()
Example #13
Source File: locks_test.py From tornado-zh with MIT License | 6 votes |
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)
Example #14
Source File: locks_test.py From tornado-zh with MIT License | 6 votes |
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)
Example #15
Source File: locks_test.py From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International | 6 votes |
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)
Example #16
Source File: locks_test.py From tornado-zh with MIT License | 6 votes |
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)
Example #17
Source File: locks_test.py From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International | 6 votes |
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)
Example #18
Source File: client.py From tredis with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, hosts, on_close=None, io_loop=None, clustering=False, auto_connect=True): """Create a new instance of the ``Client`` class. :param hosts: A list of host connection values. :type hosts: list(dict) :param io_loop: Override the current Tornado IOLoop instance :type io_loop: tornado.ioloop.IOLoop :param method on_close: The method to call if the connection is closed :param bool clustering: Toggle the cluster support in the client :param bool auto_connect: Toggle the auto-connect on creation feature """ self._buffer = bytes() self._busy = locks.Lock() self._closing = False self._cluster = {} self._clustering = clustering self._connected = locks.Event() self._connect_future = concurrent.Future() self._connection = None self._discovery = False self._hosts = hosts self._on_close_callback = on_close self._reader = hiredis.Reader() self.io_loop = io_loop or ioloop.IOLoop.current() if not self._clustering: if len(hosts) > 1: raise ValueError('Too many hosts for non-clustering mode') if auto_connect: LOGGER.debug('Auto-connecting') self.connect()
Example #19
Source File: locks_test.py From pySINDy with MIT License | 5 votes |
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
Example #20
Source File: locks_test.py From pySINDy with MIT License | 5 votes |
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
Example #21
Source File: handlers.py From nbgitpuller with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # We use this lock to make sure that only one sync operation # can be happening at a time. Git doesn't like concurrent use! if 'git_lock' not in self.settings: self.settings['git_lock'] = locks.Lock()
Example #22
Source File: locks_test.py From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
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
Example #23
Source File: locks_test.py From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
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
Example #24
Source File: locks_test.py From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
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(asyncio.ensure_future(lock.acquire()).done())
Example #25
Source File: locks_test.py From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
def test_repr(self): lock = locks.Lock() # No errors. repr(lock) lock.acquire() repr(lock)
Example #26
Source File: pubnub_tornado.py From jarvis with GNU General Public License v2.0 | 5 votes |
def __init__(self, provided_max_sequence): super(TornadoPublishSequenceManager, self).__init__(provided_max_sequence) self._lock = Lock() self._ioloop = ioloop
Example #27
Source File: locks_test.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def test_repr(self): lock = locks.Lock() # No errors. repr(lock) lock.acquire() repr(lock)
Example #28
Source File: locks_test.py From EventGhost with GNU General Public License v2.0 | 5 votes |
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())
Example #29
Source File: locks_test.py From pySINDy with MIT License | 5 votes |
def test_repr(self): lock = locks.Lock() # No errors. repr(lock) lock.acquire() repr(lock)
Example #30
Source File: locks_test.py From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
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())