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


Python trio.TASK_STATUS_IGNORED属性代码示例

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


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

示例1: handle_lifespan

# 需要导入模块: import trio [as 别名]
# 或者: from trio import TASK_STATUS_IGNORED [as 别名]
def handle_lifespan(
        self, *, task_status: trio._core._run._TaskStatus = trio.TASK_STATUS_IGNORED
    ) -> None:
        task_status.started()
        scope = {"type": "lifespan", "asgi": {"spec_version": "2.0"}}
        try:
            await invoke_asgi(self.app, scope, self.asgi_receive, self.asgi_send)
        except LifespanFailure:
            # Lifespan failures should crash the server
            raise
        except Exception:
            self.supported = False
            await self.config.log.exception(
                "ASGI Framework Lifespan error, continuing without Lifespan support"
            )
        finally:
            await self.app_send_channel.aclose()
            await self.app_receive_channel.aclose() 
开发者ID:pgjones,项目名称:hypercorn,代码行数:20,代码来源:lifespan.py

示例2: _start

# 需要导入模块: import trio [as 别名]
# 或者: from trio import TASK_STATUS_IGNORED [as 别名]
def _start(self, *, task_status=trio.TASK_STATUS_IGNORED):
        assert not self.started.is_set()
        self._trio_token = trio.hazmat.current_trio_token()
        self._send_job_channel, recv_job_channel = trio.open_memory_channel(1)
        try:
            async with trio.open_service_nursery() as nursery, recv_job_channel:
                self._cancel_scope = nursery.cancel_scope
                self.started.set()
                task_status.started()
                while True:
                    job = await recv_job_channel.receive()
                    assert job.status is None
                    await nursery.start(job._run_fn)

        finally:
            self._stopped.set() 
开发者ID:Scille,项目名称:parsec-cloud,代码行数:18,代码来源:trio_thread.py

示例3: test_monitor_crash

# 需要导入模块: import trio [as 别名]
# 或者: from trio import TASK_STATUS_IGNORED [as 别名]
def test_monitor_crash(running_backend, event_bus, alice, during_bootstrap):
    async def _bad_monitor(*, task_status=trio.TASK_STATUS_IGNORED):
        if during_bootstrap:
            raise RuntimeError("D'oh !")
        task_status.started()
        await trio.sleep(0)
        raise RuntimeError("D'oh !")

    conn = BackendAuthenticatedConn(
        alice.organization_addr, alice.device_id, alice.signing_key, event_bus
    )
    with event_bus.listen() as spy:
        conn.register_monitor(_bad_monitor)
        async with conn.run():
            await spy.wait_with_timeout(
                CoreEvent.BACKEND_CONNECTION_CHANGED,
                {"status": BackendConnStatus.CRASHED, "status_exc": spy.ANY},
            )
            assert conn.status == BackendConnStatus.CRASHED

            # Test command not possible
            with pytest.raises(BackendNotAvailable) as exc:
                await conn.cmds.ping()
            assert str(exc.value) == "Backend connection manager has crashed: D'oh !" 
开发者ID:Scille,项目名称:parsec-cloud,代码行数:26,代码来源:test_authenticated_conn.py

示例4: run

# 需要导入模块: import trio [as 别名]
# 或者: from trio import TASK_STATUS_IGNORED [as 别名]
def run(self, *, task_status=trio.TASK_STATUS_IGNORED):
        '''
        Run the crawl manager.

        You should call ``await nursery.start(crawl_manager.run)`` to ensure
        that the crawl manager is ready before calling any of its job methods.

        :returns: This function runs until cancelled.
        '''
        max_sequence = await self._db.get_max_sequence()
        self._sequence = itertools.count(start=max_sequence + 1)
        logger.info('%r Sequence initialized to %s', self, max_sequence + 1)

        async with trio.open_nursery() as nursery:
            self._nursery = nursery
            task_status.started()
            await trio.sleep_forever() 
开发者ID:HyperionGray,项目名称:starbelly,代码行数:19,代码来源:job.py

示例5: run

# 需要导入模块: import trio [as 别名]
# 或者: from trio import TASK_STATUS_IGNORED [as 别名]
def run(self, *, task_status=trio.TASK_STATUS_IGNORED):
        '''
        Run the websocket server.

        To ensure that the server is ready, call ``await
        nursery.start(server.run)``.

        :returns: Runs until cancelled.
        '''
        logger.info('Starting server on %s:%d', self._host, self._port)
        async with trio.open_nursery() as nursery:
            serve_fn = partial(serve_websocket, self._handle_connection,
                self._host, self._port, ssl_context=None,
                handler_nursery=nursery)
            server = await nursery.start(serve_fn, name='Connection Listener')
            self._port = server.port
            task_status.started()
        logger.info('Server stopped') 
开发者ID:HyperionGray,项目名称:starbelly,代码行数:20,代码来源:__init__.py

示例6: run

# 需要导入模块: import trio [as 别名]
# 或者: from trio import TASK_STATUS_IGNORED [as 别名]
def run(self, *, task_status=trio.TASK_STATUS_IGNORED):
        '''
        Start serving incoming connections requests.

        This method supports the Trio nursery start protocol: ``server = await
        nursery.start(server.run, …)``. It will block until the server is 
        accepting connections and then return a :class:`WebSocketServer` object.

        :param task_status: Part of the Trio nursery start protocol.
        :returns: This method never returns unless cancelled.
        '''
        async with trio.open_nursery() as nursery:
            serve_listeners = partial(trio.serve_listeners,
                self._handle_connection, self._listeners,
                handler_nursery=self._handler_nursery)
            await nursery.start(serve_listeners)
            logger.debug('Listening on %s',
                ','.join([str(l) for l in self.listeners]))
            task_status.started(self)
            await trio.sleep_forever() 
开发者ID:HyperionGray,项目名称:trio-websocket,代码行数:22,代码来源:_impl.py

示例7: _manage_peers

# 需要导入模块: import trio [as 别名]
# 或者: from trio import TASK_STATUS_IGNORED [as 别名]
def _manage_peers(
        self, task_status: TaskStatus[None] = trio.TASK_STATUS_IGNORED
    ) -> None:
        task_status.started()
        async with self._peer_updates:
            async for peer_id, update in self._peer_updates:
                if isinstance(update, Status):
                    sync_request = self._determine_sync_request(peer_id, update)
                    if sync_request:
                        await self._sync_notifier.send(sync_request)
                elif isinstance(update, GoodbyeReason):
                    self.logger.debug(
                        "recv'd goodbye from %s with reason: %s", peer_id, update
                    )
                    await self._host.drop_peer(peer_id)
                elif isinstance(update, MetaDataSeqNumber):
                    # TODO: track peers and their metadata
                    self.logger.debug(
                        "recv'd ping from %s with seq number: %s", peer_id, update
                    ) 
开发者ID:ethereum,项目名称:trinity,代码行数:22,代码来源:full.py

示例8: serve

# 需要导入模块: import trio [as 别名]
# 或者: from trio import TASK_STATUS_IGNORED [as 别名]
def serve(
    app: ASGIFramework,
    config: Config,
    *,
    shutdown_trigger: Optional[Callable[..., Awaitable[None]]] = None,
    task_status: trio._core._run._TaskStatus = trio.TASK_STATUS_IGNORED,
) -> None:
    """Serve an ASGI framework app given the config.

    This allows for a programmatic way to serve an ASGI framework, it
    can be used via,

    .. code-block:: python

        trio.run(partial(serve, app, config))

    It is assumed that the event-loop is configured before calling
    this function, therefore configuration values that relate to loop
    setup or process setup are ignored.

    Arguments:
        app: The ASGI application to serve.
        config: A Hypercorn configuration object.
        shutdown_trigger: This should return to trigger a graceful
            shutdown.
    """
    if config.debug:
        warnings.warn("The config `debug` has no affect when using serve", Warning)
    if config.workers != 1:
        warnings.warn("The config `workers` has no affect when using serve", Warning)

    await worker_serve(app, config, shutdown_trigger=shutdown_trigger, task_status=task_status) 
开发者ID:pgjones,项目名称:hypercorn,代码行数:34,代码来源:__init__.py

示例9: _call_later

# 需要导入模块: import trio [as 别名]
# 或者: from trio import TASK_STATUS_IGNORED [as 别名]
def _call_later(
    timeout: float,
    callback: Callable,
    task_status: trio._core._run._TaskStatus = trio.TASK_STATUS_IGNORED,
) -> None:
    cancel_scope = trio.CancelScope()
    task_status.started(cancel_scope)
    with cancel_scope:
        await trio.sleep(timeout)
        cancel_scope.shield = True
        await callback() 
开发者ID:pgjones,项目名称:hypercorn,代码行数:13,代码来源:tcp_server.py

示例10: run

# 需要导入模块: import trio [as 别名]
# 或者: from trio import TASK_STATUS_IGNORED [as 别名]
def run(
        self, task_status: trio._core._run._TaskStatus = trio.TASK_STATUS_IGNORED
    ) -> None:
        task_status.started()
        while True:
            data, address = await self.socket.recvfrom(MAX_RECV)
            await self.protocol.handle(RawData(data=data, address=address)) 
开发者ID:pgjones,项目名称:hypercorn,代码行数:9,代码来源:udp_server.py

示例11: wrap_task

# 需要导入模块: import trio [as 别名]
# 或者: from trio import TASK_STATUS_IGNORED [as 别名]
def wrap_task(cls, corofn, *args, task_status=trio.TASK_STATUS_IGNORED):
        status = cls()
        try:
            async with trio.open_service_nursery() as nursery:
                status._set_cancel_scope(nursery.cancel_scope)
                value = await nursery.start(corofn, *args)
                status._set_started_value(value)
                task_status.started(status)
        finally:
            status._set_finished() 
开发者ID:Scille,项目名称:parsec-cloud,代码行数:12,代码来源:utils.py

示例12: _run_connections

# 需要导入模块: import trio [as 别名]
# 或者: from trio import TASK_STATUS_IGNORED [as 别名]
def _run_connections(self, task_status=trio.TASK_STATUS_IGNORED):
        async with triopg.create_pool(
            self.url, min_size=self.min_connections, max_size=self.max_connections
        ) as self.pool:
            # This connection is dedicated to the notifications listening, so it
            # would only complicate stuff to include it into the connection pool
            async with triopg.connect(self.url) as self.notification_conn:
                await self.notification_conn.add_listener("app_notification", self._on_notification)
                task_status.started()
                await trio.sleep_forever() 
开发者ID:Scille,项目名称:parsec-cloud,代码行数:12,代码来源:handler.py

示例13: _instantiate_workspace_storage

# 需要导入模块: import trio [as 别名]
# 或者: from trio import TASK_STATUS_IGNORED [as 别名]
def _instantiate_workspace_storage(self, workspace_id: EntryID) -> WorkspaceStorage:
        path = self.path / str(workspace_id)

        async def workspace_storage_task(task_status=trio.TASK_STATUS_IGNORED):
            async with WorkspaceStorage.run(self.device, path, workspace_id) as workspace_storage:
                task_status.started(workspace_storage)
                await trio.sleep_forever()

        return await self._workspace_storage_nursery.start(workspace_storage_task) 
开发者ID:Scille,项目名称:parsec-cloud,代码行数:11,代码来源:userfs.py

示例14: _run_fn

# 需要导入模块: import trio [as 别名]
# 或者: from trio import TASK_STATUS_IGNORED [as 别名]
def _run_fn(self, *, task_status=trio.TASK_STATUS_IGNORED):
        with trio.CancelScope() as self.cancel_scope:
            task_status.started()
            self._started.set()

            try:
                if not iscoroutinefunction(self._fn):
                    result = self._fn(*self._args, **self._kwargs)
                else:
                    result = await self._fn(*self._args, **self._kwargs)
                self.set_result(result)

            except Exception as exc:
                self.set_exception(exc)

            except trio.Cancelled as exc:
                self.set_cancelled(exc)
                raise

            except trio.MultiError as exc:
                cancelled_errors, other_exceptions = split_multi_error(exc)
                if other_exceptions:
                    self.set_exception(other_exceptions)
                else:
                    self.set_cancelled(cancelled_errors)
                if cancelled_errors:
                    raise cancelled_errors 
开发者ID:Scille,项目名称:parsec-cloud,代码行数:29,代码来源:trio_thread.py

示例15: serve_tcp_testbed

# 需要导入模块: import trio [as 别名]
# 或者: from trio import TASK_STATUS_IGNORED [as 别名]
def serve_tcp_testbed(unused_tcp_port):
    async def _serve_tcp_testbed(*conns):
        host = "127.0.0.1"
        send_channel, receive_channel = trio.open_memory_channel(0)

        async def _serve_client(stream):
            server_fn = await receive_channel.receive()
            transport = await Transport.init_for_server(stream)
            await server_fn(transport)

        async def _store_handlers(*, task_status=trio.TASK_STATUS_IGNORED):
            async with trio.open_service_nursery() as handler_nursery:
                task_status.started(handler_nursery)
                await trio.sleep_forever()

        async with trio.open_service_nursery() as nursery:
            handler_nursery = await nursery.start(_store_handlers)
            await nursery.start(
                partial(
                    trio.serve_tcp, _serve_client, unused_tcp_port, handler_nursery=handler_nursery
                )
            )
            assert not handler_nursery.child_tasks

            for client_fn, server_fn in conns:
                stream = await trio.open_tcp_stream(host, unused_tcp_port)
                await send_channel.send(server_fn)

                transport = await Transport.init_for_client(stream, host)
                await client_fn(transport)

                await trio.testing.wait_all_tasks_blocked()
                # No pending connections should remain
                assert not handler_nursery.child_tasks

            await send_channel.aclose()
            nursery.cancel_scope.cancel()

    return _serve_tcp_testbed 
开发者ID:Scille,项目名称:parsec-cloud,代码行数:41,代码来源:test_transport.py


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