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


Python stack_context.wrap方法代码示例

本文整理汇总了Python中tornado.stack_context.wrap方法的典型用法代码示例。如果您正苦于以下问题:Python stack_context.wrap方法的具体用法?Python stack_context.wrap怎么用?Python stack_context.wrap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tornado.stack_context的用法示例。


在下文中一共展示了stack_context.wrap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _handle_connect

# 需要导入模块: from tornado import stack_context [as 别名]
# 或者: from tornado.stack_context import wrap [as 别名]
def _handle_connect(self):
        # Call the superclass method to check for errors.
        super(SSLIOStream, self)._handle_connect()
        if self.closed():
            return
        # When the connection is complete, wrap the socket for SSL
        # traffic.  Note that we do this by overriding _handle_connect
        # instead of by passing a callback to super().connect because
        # user callbacks are enqueued asynchronously on the IOLoop,
        # but since _handle_events calls _handle_connect immediately
        # followed by _handle_write we need this to be synchronous.
        #
        # The IOLoop will get confused if we swap out self.socket while the
        # fd is registered, so remove it now and re-register after
        # wrap_socket().
        self.io_loop.remove_handler(self.socket)
        old_state = self._state
        self._state = None
        self.socket = ssl_wrap_socket(self.socket, self._ssl_options,
                                      server_hostname=self._server_hostname,
                                      do_handshake_on_connect=False)
        self._add_io_state(old_state) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:24,代码来源:iostream.py

示例2: set_exit_callback

# 需要导入模块: from tornado import stack_context [as 别名]
# 或者: from tornado.stack_context import wrap [as 别名]
def set_exit_callback(self, callback):
        """Runs ``callback`` when this process exits.

        The callback takes one argument, the return code of the process.

        This method uses a ``SIGCHLD`` handler, which is a global setting
        and may conflict if you have other libraries trying to handle the
        same signal.  If you are using more than one ``IOLoop`` it may
        be necessary to call `Subprocess.initialize` first to designate
        one ``IOLoop`` to run the signal handlers.

        In many cases a close callback on the stdout or stderr streams
        can be used as an alternative to an exit callback if the
        signal handler is causing a problem.
        """
        self._exit_callback = stack_context.wrap(callback)
        Subprocess.initialize(self.io_loop)
        Subprocess._waiting[self.pid] = self
        Subprocess._try_cleanup_process(self.pid) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:21,代码来源:process.py

示例3: test_pre_wrap_with_args

# 需要导入模块: from tornado import stack_context [as 别名]
# 或者: from tornado.stack_context import wrap [as 别名]
def test_pre_wrap_with_args(self):
        # Same as test_pre_wrap, but the function takes arguments.
        # Implementation note: The function must not be wrapped in a
        # functools.partial until after it has been passed through
        # stack_context.wrap
        def f1(foo, bar):
            self.assertIn('c1', self.active_contexts)
            self.assertNotIn('c2', self.active_contexts)
            self.stop((foo, bar))

        with StackContext(functools.partial(self.context, 'c1')):
            wrapped = wrap(f1)

        with StackContext(functools.partial(self.context, 'c2')):
            self.add_callback(wrapped, 1, bar=2)

        result = self.wait()
        self.assertEqual(result, (1, 2)) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:20,代码来源:ioloop_test.py

示例4: write

# 需要导入模块: from tornado import stack_context [as 别名]
# 或者: from tornado.stack_context import wrap [as 别名]
def write(self, chunk, callback=None):
        """Implements `.HTTPConnection.write`.

        For backwards compatibility is is allowed but deprecated to
        skip `write_headers` and instead call `write()` with a
        pre-encoded header block.
        """
        future = None
        if self.stream.closed():
            future = self._write_future = Future()
            self._write_future.set_exception(iostream.StreamClosedError())
            self._write_future.exception()
        else:
            if callback is not None:
                self._write_callback = stack_context.wrap(callback)
            else:
                future = self._write_future = Future()
            self._pending_write = self.stream.write(self._format_chunk(chunk))
            self._pending_write.add_done_callback(self._on_write_complete)
        return future 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:22,代码来源:http1connection.py

示例5: __init__

# 需要导入模块: from tornado import stack_context [as 别名]
# 或者: from tornado.stack_context import wrap [as 别名]
def __init__(self, stream, address, request_callback, no_keep_alive=False,
                 xheaders=False, protocol=None):
        self.stream = stream
        self.address = address
        # Save the socket's address family now so we know how to
        # interpret self.address even after the stream is closed
        # and its socket attribute replaced with None.
        self.address_family = stream.socket.family
        self.request_callback = request_callback
        self.no_keep_alive = no_keep_alive
        self.xheaders = xheaders
        self.protocol = protocol
        self._clear_request_state()
        # Save stack context here, outside of any request.  This keeps
        # contexts from one request from leaking into the next.
        self._header_callback = stack_context.wrap(self._on_headers)
        self.stream.set_close_callback(self._on_connection_close)
        self.stream.read_until(b"\r\n\r\n", self._header_callback) 
开发者ID:viewfinderco,项目名称:viewfinder,代码行数:20,代码来源:httpserver.py

示例6: read_until_close

# 需要导入模块: from tornado import stack_context [as 别名]
# 或者: from tornado.stack_context import wrap [as 别名]
def read_until_close(self, callback, streaming_callback=None):
        """Reads all data from the socket until it is closed.

        If a ``streaming_callback`` is given, it will be called with chunks
        of data as they become available, and the argument to the final
        ``callback`` will be empty.  Otherwise, the ``callback`` gets the
        data as an argument.

        Subject to ``max_buffer_size`` limit from `IOStream` constructor if
        a ``streaming_callback`` is not used.
        """
        self._set_read_callback(callback)
        self._streaming_callback = stack_context.wrap(streaming_callback)
        if self.closed():
            if self._streaming_callback is not None:
                self._run_callback(self._streaming_callback,
                                   self._consume(self._read_buffer_size))
            self._run_callback(self._read_callback,
                               self._consume(self._read_buffer_size))
            self._streaming_callback = None
            self._read_callback = None
            return
        self._read_until_close = True
        self._streaming_callback = stack_context.wrap(streaming_callback)
        self._try_inline_read() 
开发者ID:viewfinderco,项目名称:viewfinder,代码行数:27,代码来源:iostream.py

示例7: call_wrapped_inner

# 需要导入模块: from tornado import stack_context [as 别名]
# 或者: from tornado.stack_context import wrap [as 别名]
def call_wrapped_inner(self, queue, count):
        if count < 0:
            return
        with self.make_context():
            queue.append(stack_context.wrap(
                functools.partial(self.call_wrapped_inner, queue, count - 1))) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:8,代码来源:stack_context_benchmark.py

示例8: body_producer

# 需要导入模块: from tornado import stack_context [as 别名]
# 或者: from tornado.stack_context import wrap [as 别名]
def body_producer(self, value):
        self._body_producer = stack_context.wrap(value) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:4,代码来源:httpclient.py

示例9: streaming_callback

# 需要导入模块: from tornado import stack_context [as 别名]
# 或者: from tornado.stack_context import wrap [as 别名]
def streaming_callback(self, value):
        self._streaming_callback = stack_context.wrap(value) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:4,代码来源:httpclient.py

示例10: header_callback

# 需要导入模块: from tornado import stack_context [as 别名]
# 或者: from tornado.stack_context import wrap [as 别名]
def header_callback(self, value):
        self._header_callback = stack_context.wrap(value) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:4,代码来源:httpclient.py

示例11: add_handler

# 需要导入模块: from tornado import stack_context [as 别名]
# 或者: from tornado.stack_context import wrap [as 别名]
def add_handler(self, fd, handler, events):
        if fd in self.fds:
            raise ValueError('fd %s added twice' % fd)
        fd, fileobj = self.split_fd(fd)
        self.fds[fd] = _FD(fd, fileobj, wrap(handler))
        if events & tornado.ioloop.IOLoop.READ:
            self.fds[fd].reading = True
            self.reactor.addReader(self.fds[fd])
        if events & tornado.ioloop.IOLoop.WRITE:
            self.fds[fd].writing = True
            self.reactor.addWriter(self.fds[fd]) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:13,代码来源:twisted.py

示例12: add_timeout

# 需要导入模块: from tornado import stack_context [as 别名]
# 或者: from tornado.stack_context import wrap [as 别名]
def add_timeout(self, deadline, callback, *args, **kwargs):
        # This method could be simplified (since tornado 4.0) by
        # overriding call_at instead of add_timeout, but we leave it
        # for now as a test of backwards-compatibility.
        if isinstance(deadline, numbers.Real):
            delay = max(deadline - self.time(), 0)
        elif isinstance(deadline, datetime.timedelta):
            delay = timedelta_to_seconds(deadline)
        else:
            raise TypeError("Unsupported deadline %r")
        return self.reactor.callLater(
            delay, self._run_callback,
            functools.partial(wrap(callback), *args, **kwargs)) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:15,代码来源:twisted.py

示例13: add_callback

# 需要导入模块: from tornado import stack_context [as 别名]
# 或者: from tornado.stack_context import wrap [as 别名]
def add_callback(self, callback, *args, **kwargs):
        self.reactor.callFromThread(
            self._run_callback,
            functools.partial(wrap(callback), *args, **kwargs)) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:6,代码来源:twisted.py

示例14: add_handler

# 需要导入模块: from tornado import stack_context [as 别名]
# 或者: from tornado.stack_context import wrap [as 别名]
def add_handler(self, fd, handler, events):
        fd, fileobj = self.split_fd(fd)
        if fd in self.handlers:
            raise ValueError("fd %s added twice" % fd)
        self.handlers[fd] = (fileobj, stack_context.wrap(handler))
        if events & IOLoop.READ:
            self.asyncio_loop.add_reader(
                fd, self._handle_events, fd, IOLoop.READ)
            self.readers.add(fd)
        if events & IOLoop.WRITE:
            self.asyncio_loop.add_writer(
                fd, self._handle_events, fd, IOLoop.WRITE)
            self.writers.add(fd) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:15,代码来源:asyncio.py

示例15: call_at

# 需要导入模块: from tornado import stack_context [as 别名]
# 或者: from tornado.stack_context import wrap [as 别名]
def call_at(self, when, callback, *args, **kwargs):
        # asyncio.call_at supports *args but not **kwargs, so bind them here.
        # We do not synchronize self.time and asyncio_loop.time, so
        # convert from absolute to relative.
        return self.asyncio_loop.call_later(
            max(0, when - self.time()), self._run_callback,
            functools.partial(stack_context.wrap(callback), *args, **kwargs)) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:9,代码来源:asyncio.py


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