当前位置: 首页>>代码示例>>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;未经允许,请勿转载。