當前位置: 首頁>>代碼示例>>Python>>正文


Python locks.Event方法代碼示例

本文整理匯總了Python中tornado.locks.Event方法的典型用法代碼示例。如果您正苦於以下問題:Python locks.Event方法的具體用法?Python locks.Event怎麽用?Python locks.Event使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tornado.locks的用法示例。


在下文中一共展示了locks.Event方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from tornado import locks [as 別名]
# 或者: from tornado.locks import Event [as 別名]
def __init__(self, *args, **kwargs):
        if 'io_loop' in kwargs:
            self._ioloop = kwargs.pop('io_loop')
        else:
            self._ioloop = ioloop.IOLoop.current()

        super(XBeeBase, self).__init__(*args, **kwargs)

        self._running = Event()
        self._running.set()

        self._frame_future = None
        self._frame_queue = deque()

        if self._callback:
            # Make Non-Blocking
            self.serial.timeout = 0
            self.process_frames()

        self._ioloop.add_handler(self.serial.fd,
                                 self._process_input,
                                 ioloop.IOLoop.READ) 
開發者ID:niolabs,項目名稱:python-xbee,代碼行數:24,代碼來源:base.py

示例2: test_close_callback_with_pending_read

# 需要導入模塊: from tornado import locks [as 別名]
# 或者: from tornado.locks import Event [as 別名]
def test_close_callback_with_pending_read(self):
        # Regression test for a bug that was introduced in 2.3
        # where the IOStream._close_callback would never be called
        # if there were pending reads.
        OK = b"OK\r\n"
        rs, ws = yield self.make_iostream_pair()
        event = Event()
        rs.set_close_callback(event.set)
        try:
            ws.write(OK)
            res = yield rs.read_until(b"\r\n")
            self.assertEqual(res, OK)

            ws.close()
            rs.read_until(b"\r\n")
            # If _close_callback (self.stop) is not called,
            # an AssertionError: Async operation timed out after 5 seconds
            # will be raised.
            yield event.wait()
        finally:
            ws.close()
            rs.close() 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:24,代碼來源:iostream_test.py

示例3: test_read_until_max_bytes_inline

# 需要導入模塊: from tornado import locks [as 別名]
# 或者: from tornado.locks import Event [as 別名]
def test_read_until_max_bytes_inline(self):
        rs, ws = yield self.make_iostream_pair()
        closed = Event()
        rs.set_close_callback(closed.set)
        try:
            # Similar to the error case in the previous test, but the
            # ws writes first so rs reads are satisfied
            # inline.  For consistency with the out-of-line case, we
            # do not raise the error synchronously.
            ws.write(b"123456")
            with ExpectLog(gen_log, "Unsatisfiable read"):
                with self.assertRaises(StreamClosedError):
                    yield rs.read_until(b"def", max_bytes=5)
            yield closed.wait()
        finally:
            ws.close()
            rs.close() 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:19,代碼來源:iostream_test.py

示例4: test_read_until_regex_max_bytes_inline

# 需要導入模塊: from tornado import locks [as 別名]
# 或者: from tornado.locks import Event [as 別名]
def test_read_until_regex_max_bytes_inline(self):
        rs, ws = yield self.make_iostream_pair()
        closed = Event()
        rs.set_close_callback(closed.set)
        try:
            # Similar to the error case in the previous test, but the
            # ws writes first so rs reads are satisfied
            # inline.  For consistency with the out-of-line case, we
            # do not raise the error synchronously.
            ws.write(b"123456")
            with ExpectLog(gen_log, "Unsatisfiable read"):
                rs.read_until_regex(b"def", max_bytes=5)
                yield closed.wait()
        finally:
            ws.close()
            rs.close() 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:18,代碼來源:iostream_test.py

示例5: test_async_read_error_logging

# 需要導入模塊: from tornado import locks [as 別名]
# 或者: from tornado.locks import Event [as 別名]
def test_async_read_error_logging(self):
        # Socket errors on asynchronous reads should be logged (but only
        # once).
        server, client = yield self.make_iostream_pair()
        closed = Event()
        server.set_close_callback(closed.set)
        try:
            # Start a read that will be fulfilled asynchronously.
            server.read_bytes(1)
            client.write(b"a")
            # Stub out read_from_fd to make it fail.

            def fake_read_from_fd():
                os.close(server.socket.fileno())
                server.__class__.read_from_fd(server)

            server.read_from_fd = fake_read_from_fd
            # This log message is from _handle_read (not read_from_fd).
            with ExpectLog(gen_log, "error on read"):
                yield closed.wait()
        finally:
            server.close()
            client.close() 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:25,代碼來源:iostream_test.py

示例6: test_leaked_coroutine

# 需要導入模塊: from tornado import locks [as 別名]
# 或者: from tornado.locks import Event [as 別名]
def test_leaked_coroutine(self):
        # This test verifies that "leaked" coroutines are shut down
        # without triggering warnings like "task was destroyed but it
        # is pending". If this test were to fail, it would fail
        # because runtests.py detected unexpected output to stderr.
        event = Event()

        async def callback():
            try:
                await event.wait()
            except asyncio.CancelledError:
                pass

        self.io_loop.add_callback(callback)
        self.io_loop.add_callback(self.stop)
        self.wait() 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:18,代碼來源:testing_test.py

示例7: test_http10_no_content_length

# 需要導入模塊: from tornado import locks [as 別名]
# 或者: from tornado.locks import Event [as 別名]
def test_http10_no_content_length(self):
        # Regression test for a bug in which can_keep_alive would crash
        # for an HTTP/1.0 (not 1.1) response with no content-length.
        conn = HTTP1Connection(self.client_stream, True)
        self.server_stream.write(b"HTTP/1.0 200 Not Modified\r\n\r\nhello")
        self.server_stream.close()

        event = Event()
        test = self
        body = []

        class Delegate(HTTPMessageDelegate):
            def headers_received(self, start_line, headers):
                test.code = start_line.code

            def data_received(self, data):
                body.append(data)

            def finish(self):
                event.set()

        yield conn.read_response(Delegate())
        yield event.wait()
        self.assertEqual(self.code, 200)
        self.assertEqual(b"".join(body), b"hello") 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:27,代碼來源:http1connection_test.py

示例8: test_async_read_error_logging

# 需要導入模塊: from tornado import locks [as 別名]
# 或者: from tornado.locks import Event [as 別名]
def test_async_read_error_logging(self):
        # Socket errors on asynchronous reads should be logged (but only
        # once).
        server, client = yield self.make_iostream_pair()
        closed = Event()
        server.set_close_callback(closed.set)
        try:
            # Start a read that will be fulfilled asynchronously.
            server.read_bytes(1)
            client.write(b'a')
            # Stub out read_from_fd to make it fail.

            def fake_read_from_fd():
                os.close(server.socket.fileno())
                server.__class__.read_from_fd(server)
            server.read_from_fd = fake_read_from_fd
            # This log message is from _handle_read (not read_from_fd).
            with ExpectLog(gen_log, "error on read"):
                yield closed.wait()
        finally:
            server.close()
            client.close() 
開發者ID:tp4a,項目名稱:teleport,代碼行數:24,代碼來源:iostream_test.py

示例9: asyncSetUp

# 需要導入模塊: from tornado import locks [as 別名]
# 或者: from tornado.locks import Event [as 別名]
def asyncSetUp(self):
        listener, port = bind_unused_port()
        event = Event()

        def accept_callback(conn, addr):
            self.server_stream = IOStream(conn)
            self.addCleanup(self.server_stream.close)
            event.set()

        add_accept_handler(listener, accept_callback)
        self.client_stream = IOStream(socket.socket())
        self.addCleanup(self.client_stream.close)
        yield [self.client_stream.connect(('127.0.0.1', port)),
               event.wait()]
        self.io_loop.remove_handler(listener)
        listener.close() 
開發者ID:tp4a,項目名稱:teleport,代碼行數:18,代碼來源:http1connection_test.py

示例10: test_http10_no_content_length

# 需要導入模塊: from tornado import locks [as 別名]
# 或者: from tornado.locks import Event [as 別名]
def test_http10_no_content_length(self):
        # Regression test for a bug in which can_keep_alive would crash
        # for an HTTP/1.0 (not 1.1) response with no content-length.
        conn = HTTP1Connection(self.client_stream, True)
        self.server_stream.write(b"HTTP/1.0 200 Not Modified\r\n\r\nhello")
        self.server_stream.close()

        event = Event()
        test = self
        body = []

        class Delegate(HTTPMessageDelegate):
            def headers_received(self, start_line, headers):
                test.code = start_line.code

            def data_received(self, data):
                body.append(data)

            def finish(self):
                event.set()

        yield conn.read_response(Delegate())
        yield event.wait()
        self.assertEqual(self.code, 200)
        self.assertEqual(b''.join(body), b'hello') 
開發者ID:tp4a,項目名稱:teleport,代碼行數:27,代碼來源:http1connection_test.py

示例11: test_prepare_curl_callback_stack_context

# 需要導入模塊: from tornado import locks [as 別名]
# 或者: from tornado.locks import Event [as 別名]
def test_prepare_curl_callback_stack_context(self):
        exc_info = []
        error_event = Event()

        def error_handler(typ, value, tb):
            exc_info.append((typ, value, tb))
            error_event.set()
            return True

        with ignore_deprecation():
            with ExceptionStackContext(error_handler):
                request = HTTPRequest(self.get_url('/custom_reason'),
                                      prepare_curl_callback=lambda curl: 1 / 0)
        yield [error_event.wait(), self.http_client.fetch(request)]
        self.assertEqual(1, len(exc_info))
        self.assertIs(exc_info[0][0], ZeroDivisionError) 
開發者ID:tp4a,項目名稱:teleport,代碼行數:18,代碼來源:curl_httpclient_test.py

示例12: __init__

# 需要導入模塊: from tornado import locks [as 別名]
# 或者: from tornado.locks import Event [as 別名]
def __init__(self, maxsize=0):
        if maxsize is None:
            raise TypeError("maxsize can't be None")

        if maxsize < 0:
            raise ValueError("maxsize can't be negative")

        self._maxsize = maxsize
        self._init()
        self._getters = collections.deque([])  # Futures.
        self._putters = collections.deque([])  # Pairs of (item, Future).
        self._unfinished_tasks = 0
        self._finished = Event()
        self._finished.set() 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:16,代碼來源:queues.py

示例13: test_repr

# 需要導入模塊: from tornado import locks [as 別名]
# 或者: from tornado.locks import Event [as 別名]
def test_repr(self):
        event = locks.Event()
        self.assertTrue('clear' in str(event))
        self.assertFalse('set' in str(event))
        event.set()
        self.assertFalse('clear' in str(event))
        self.assertTrue('set' in str(event)) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:9,代碼來源:locks_test.py

示例14: test_event

# 需要導入模塊: from tornado import locks [as 別名]
# 或者: from tornado.locks import Event [as 別名]
def test_event(self):
        e = locks.Event()
        future_0 = e.wait()
        e.set()
        future_1 = e.wait()
        e.clear()
        future_2 = e.wait()

        self.assertTrue(future_0.done())
        self.assertTrue(future_1.done())
        self.assertFalse(future_2.done()) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:13,代碼來源:locks_test.py

示例15: test_event_timeout

# 需要導入模塊: from tornado import locks [as 別名]
# 或者: from tornado.locks import Event [as 別名]
def test_event_timeout(self):
        e = locks.Event()
        with self.assertRaises(TimeoutError):
            yield e.wait(timedelta(seconds=0.01))

        # After a timed-out waiter, normal operation works.
        self.io_loop.add_timeout(timedelta(seconds=0.01), e.set)
        yield e.wait(timedelta(seconds=1)) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:10,代碼來源:locks_test.py


注:本文中的tornado.locks.Event方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。