當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。