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


Python gen.convert_yielded方法代码示例

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


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

示例1: _write_body

# 需要导入模块: from tornado import gen [as 别名]
# 或者: from tornado.gen import convert_yielded [as 别名]
def _write_body(self, start_read):
        if self.request.body is not None:
            self.connection.write(self.request.body)
        elif self.request.body_producer is not None:
            fut = self.request.body_producer(self.connection.write)
            if fut is not None:
                fut = gen.convert_yielded(fut)

                def on_body_written(fut):
                    fut.result()
                    self.connection.finish()
                    if start_read:
                        self._read_response()
                self.io_loop.add_future(fut, on_body_written)
                return
        self.connection.finish()
        if start_read:
            self._read_response() 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:20,代码来源:simple_httpclient.py

示例2: _run_callback

# 需要导入模块: from tornado import gen [as 别名]
# 或者: from tornado.gen import convert_yielded [as 别名]
def _run_callback(self, callback):
        """Runs a callback with error handling.

        For use in subclasses.
        """
        try:
            ret = callback()
            if ret is not None:
                from tornado import gen
                # Functions that return Futures typically swallow all
                # exceptions and store them in the Future.  If a Future
                # makes it out to the IOLoop, ensure its exception (if any)
                # gets logged too.
                try:
                    ret = gen.convert_yielded(ret)
                except gen.BadYieldError:
                    # It's not unusual for add_callback to be used with
                    # methods returning a non-None and non-yieldable
                    # result, which should just be ignored.
                    pass
                else:
                    self.add_future(ret, lambda f: f.result())
        except Exception:
            self.handle_callback_exception(callback) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:26,代码来源:ioloop.py

示例3: _run_callback

# 需要导入模块: from tornado import gen [as 别名]
# 或者: from tornado.gen import convert_yielded [as 别名]
def _run_callback(
        self, callback: Callable, *args: Any, **kwargs: Any
    ) -> "Optional[Future[Any]]":
        """Runs the given callback with exception handling.

        If the callback is a coroutine, returns its Future. On error, aborts the
        websocket connection and returns None.
        """
        try:
            result = callback(*args, **kwargs)
        except Exception:
            self.handler.log_exception(*sys.exc_info())
            self._abort()
            return None
        else:
            if result is not None:
                result = gen.convert_yielded(result)
                assert self.stream is not None
                self.stream.io_loop.add_future(result, lambda f: f.result())
            return result 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:22,代码来源:websocket.py

示例4: _run_callback

# 需要导入模块: from tornado import gen [as 别名]
# 或者: from tornado.gen import convert_yielded [as 别名]
def _run_callback(self, callback, *args, **kwargs):
        """Runs the given callback with exception handling.

        If the callback is a coroutine, returns its Future. On error, aborts the
        websocket connection and returns None.
        """
        try:
            result = callback(*args, **kwargs)
        except Exception:
            self.handler.log_exception(*sys.exc_info())
            self._abort()
        else:
            if result is not None:
                result = gen.convert_yielded(result)
                self.stream.io_loop.add_future(result, lambda f: f.result())
            return result 
开发者ID:tp4a,项目名称:teleport,代码行数:18,代码来源:websocket.py

示例5: _run_callback

# 需要导入模块: from tornado import gen [as 别名]
# 或者: from tornado.gen import convert_yielded [as 别名]
def _run_callback(self, callback):
        """Runs a callback with error handling.

        For use in subclasses.
        """
        try:
            ret = callback()
            if ret is not None:
                from tornado import gen
                # Functions that return Futures typically swallow all
                # exceptions and store them in the Future.  If a Future
                # makes it out to the IOLoop, ensure its exception (if any)
                # gets logged too.
                try:
                    ret = gen.convert_yielded(ret)
                except gen.BadYieldError:
                    # It's not unusual for add_callback to be used with
                    # methods returning a non-None and non-yieldable
                    # result, which should just be ignored.
                    pass
                else:
                    self.add_future(ret, self._discard_future_result)
        except Exception:
            self.handle_callback_exception(callback) 
开发者ID:tp4a,项目名称:teleport,代码行数:26,代码来源:ioloop.py

示例6: _do_submit_job

# 需要导入模块: from tornado import gen [as 别名]
# 或者: from tornado.gen import convert_yielded [as 别名]
def _do_submit_job(self, job, run_times):
        def callback(f):
            try:
                events = f.result()
            except BaseException:
                self._run_job_error(job.id, *sys.exc_info()[1:])
            else:
                self._run_job_success(job.id, events)

        if iscoroutinefunction(job.func):
            f = run_coroutine_job(job, job._jobstore_alias, run_times, self._logger.name)
        else:
            f = self.executor.submit(run_job, job, job._jobstore_alias, run_times,
                                     self._logger.name)

        f = convert_yielded(f)
        f.add_done_callback(callback) 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:19,代码来源:tornado.py

示例7: _do_submit_job

# 需要导入模块: from tornado import gen [as 别名]
# 或者: from tornado.gen import convert_yielded [as 别名]
def _do_submit_job(self, job, run_times):
        def callback(f):
            try:
                events = f.result()
            except BaseException:
                self._run_job_error(job.id, *sys.exc_info()[1:])
            else:
                self._run_job_success(job.id, events)

        if iscoroutinefunction_partial(job.func):
            f = run_coroutine_job(job, job._jobstore_alias, run_times, self._logger.name)
        else:
            f = self.executor.submit(run_job, job, job._jobstore_alias, run_times,
                                     self._logger.name)

        f = convert_yielded(f)
        f.add_done_callback(callback) 
开发者ID:Tautulli,项目名称:Tautulli,代码行数:19,代码来源:tornado.py

示例8: test_success

# 需要导入模块: from tornado import gen [as 别名]
# 或者: from tornado.gen import convert_yielded [as 别名]
def test_success(self):
        @inlineCallbacks
        def fn():
            if False:
                # inlineCallbacks doesn't work with regular functions;
                # must have a yield even if it's unreachable.
                yield
            returnValue(42)
        f = gen.convert_yielded(fn())
        self.assertEqual(f.result(), 42) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:12,代码来源:twisted_test.py

示例9: test_failure

# 需要导入模块: from tornado import gen [as 别名]
# 或者: from tornado.gen import convert_yielded [as 别名]
def test_failure(self):
        @inlineCallbacks
        def fn():
            if False:
                yield
            1 / 0
        f = gen.convert_yielded(fn())
        with self.assertRaises(ZeroDivisionError):
            f.result() 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:11,代码来源:twisted_test.py

示例10: execute

# 需要导入模块: from tornado import gen [as 别名]
# 或者: from tornado.gen import convert_yielded [as 别名]
def execute(self) -> Optional[Awaitable[None]]:
        # If template cache is disabled (usually in the debug mode),
        # re-compile templates and reload static files on every
        # request so you don't need to restart to see changes
        if not self.application.settings.get("compiled_template_cache", True):
            with RequestHandler._template_loader_lock:
                for loader in RequestHandler._template_loaders.values():
                    loader.reset()
        if not self.application.settings.get("static_hash_cache", True):
            StaticFileHandler.reset()

        self.handler = self.handler_class(
            self.application, self.request, **self.handler_kwargs
        )
        transforms = [t(self.request) for t in self.application.transforms]

        if self.stream_request_body:
            self.handler._prepared_future = Future()
        # Note that if an exception escapes handler._execute it will be
        # trapped in the Future it returns (which we are ignoring here,
        # leaving it to be logged when the Future is GC'd).
        # However, that shouldn't happen because _execute has a blanket
        # except handler, and we cannot easily access the IOLoop here to
        # call add_future (because of the requirement to remain compatible
        # with WSGI)
        fut = gen.convert_yielded(
            self.handler._execute(transforms, *self.path_args, **self.path_kwargs)
        )
        fut.add_done_callback(lambda f: f.result())
        # If we are streaming the request body, then execute() is finished
        # when the handler has prepared to receive the body.  If not,
        # it doesn't matter when execute() finishes (so we return None)
        return self.handler._prepared_future 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:35,代码来源:web.py

示例11: to_asyncio_future

# 需要导入模块: from tornado import gen [as 别名]
# 或者: from tornado.gen import convert_yielded [as 别名]
def to_asyncio_future(tornado_future: asyncio.Future) -> asyncio.Future:
    """Convert a Tornado yieldable object to an `asyncio.Future`.

    .. versionadded:: 4.1

    .. versionchanged:: 4.3
       Now accepts any yieldable object, not just
       `tornado.concurrent.Future`.

    .. deprecated:: 5.0
       Tornado ``Futures`` have been merged with `asyncio.Future`,
       so this method is now equivalent to `tornado.gen.convert_yielded`.
    """
    return convert_yielded(tornado_future) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:16,代码来源:asyncio.py

示例12: __init__

# 需要导入模块: from tornado import gen [as 别名]
# 或者: from tornado.gen import convert_yielded [as 别名]
def __init__(
        self,
        client: Optional[SimpleAsyncHTTPClient],
        request: HTTPRequest,
        release_callback: Callable[[], None],
        final_callback: Callable[[HTTPResponse], None],
        max_buffer_size: int,
        tcp_client: TCPClient,
        max_header_size: int,
        max_body_size: int,
    ) -> None:
        self.io_loop = IOLoop.current()
        self.start_time = self.io_loop.time()
        self.start_wall_time = time.time()
        self.client = client
        self.request = request
        self.release_callback = release_callback
        self.final_callback = final_callback
        self.max_buffer_size = max_buffer_size
        self.tcp_client = tcp_client
        self.max_header_size = max_header_size
        self.max_body_size = max_body_size
        self.code = None  # type: Optional[int]
        self.headers = None  # type: Optional[httputil.HTTPHeaders]
        self.chunks = []  # type: List[bytes]
        self._decompressor = None
        # Timeout handle returned by IOLoop.add_timeout
        self._timeout = None  # type: object
        self._sockaddr = None
        IOLoop.current().add_future(
            gen.convert_yielded(self.run()), lambda f: f.result()
        ) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:34,代码来源:simple_httpclient.py

示例13: _run_callback

# 需要导入模块: from tornado import gen [as 别名]
# 或者: from tornado.gen import convert_yielded [as 别名]
def _run_callback(self, callback: Callable[[], Any]) -> None:
        """Runs a callback with error handling.

        .. versionchanged:: 6.0

           CancelledErrors are no longer logged.
        """
        try:
            ret = callback()
            if ret is not None:
                from tornado import gen

                # Functions that return Futures typically swallow all
                # exceptions and store them in the Future.  If a Future
                # makes it out to the IOLoop, ensure its exception (if any)
                # gets logged too.
                try:
                    ret = gen.convert_yielded(ret)
                except gen.BadYieldError:
                    # It's not unusual for add_callback to be used with
                    # methods returning a non-None and non-yieldable
                    # result, which should just be ignored.
                    pass
                else:
                    self.add_future(ret, self._discard_future_result)
        except asyncio.CancelledError:
            pass
        except Exception:
            app_log.error("Exception in callback %r", callback, exc_info=True) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:31,代码来源:ioloop.py

示例14: start_serving

# 需要导入模块: from tornado import gen [as 别名]
# 或者: from tornado.gen import convert_yielded [as 别名]
def start_serving(self, delegate: httputil.HTTPServerConnectionDelegate) -> None:
        """Starts serving requests on this connection.

        :arg delegate: a `.HTTPServerConnectionDelegate`
        """
        assert isinstance(delegate, httputil.HTTPServerConnectionDelegate)
        fut = gen.convert_yielded(self._server_request_loop(delegate))
        self._serving_future = fut
        # Register the future on the IOLoop so its errors get logged.
        self.stream.io_loop.add_future(fut, lambda f: f.result()) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:12,代码来源:http1connection.py

示例15: _on_access_token

# 需要导入模块: from tornado import gen [as 别名]
# 或者: from tornado.gen import convert_yielded [as 别名]
def _on_access_token(self, future, response_fut):
        try:
            response = response_fut.result()
        except Exception:
            future.set_exception(AuthError("Could not fetch access token"))
            return

        access_token = _oauth_parse_response(response.body)
        fut = self._oauth_get_user_future(access_token)
        fut = gen.convert_yielded(fut)
        fut.add_done_callback(
            wrap(functools.partial(self._on_oauth_get_user, access_token, future))) 
开发者ID:tp4a,项目名称:teleport,代码行数:14,代码来源:auth.py


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