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


Python trio.ClosedResourceError方法代码示例

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


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

示例1: run

# 需要导入模块: import trio [as 别名]
# 或者: from trio import ClosedResourceError [as 别名]
def run(self):
        """
        Run the subscription.

        :returns: This function returns when the sync is complete.
        """
        logger.info("%r Starting", self)
        async with trio.open_nursery() as nursery:
            self._cancel_scope = nursery.cancel_scope
            await self._set_initial_job_status()
            nursery.start_soon(self._job_status_task)
            try:
                await self._run_sync()
            except (trio.BrokenResourceError, trio.ClosedResourceError):
                logger.info("%r Aborted", self)
            nursery.cancel_scope.cancel()
        try:
            await self._send_complete()
            logger.info("%r Finished", self)
        except (trio.BrokenResourceError, trio.ClosedResourceError):
            # If we can't send the completion message, then bail out.
            pass 
开发者ID:HyperionGray,项目名称:starbelly,代码行数:24,代码来源:subscription.py

示例2: get_message

# 需要导入模块: import trio [as 别名]
# 或者: from trio import ClosedResourceError [as 别名]
def get_message(self):
        '''
        Receive the next WebSocket message.

        If no message is available immediately, then this function blocks until
        a message is ready.

        If the remote endpoint closes the connection, then the caller can still
        get messages sent prior to closing. Once all pending messages have been
        retrieved, additional calls to this method will raise
        ``ConnectionClosed``. If the local endpoint closes the connection, then
        pending messages are discarded and calls to this method will immediately
        raise ``ConnectionClosed``.

        :rtype: str or bytes
        :raises ConnectionClosed: if the connection is closed.
        '''
        try:
            message = await self._recv_channel.receive()
        except (trio.ClosedResourceError, trio.EndOfChannel):
            raise ConnectionClosed(self._close_reason) from None
        return message 
开发者ID:HyperionGray,项目名称:trio-websocket,代码行数:24,代码来源:_impl.py

示例3: _send

# 需要导入模块: import trio [as 别名]
# 或者: from trio import ClosedResourceError [as 别名]
def _send(self, event):
        '''
        Send an to the remote WebSocket.

        The reader task and one or more writers might try to send messages at
        the same time, so this method uses an internal lock to serialize
        requests to send data.

        :param wsproto.events.Event event:
        '''
        data = self._wsproto.send(event)
        async with self._stream_lock:
            logger.debug('%s sending %d bytes', self, len(data))
            try:
                await self._stream.send_all(data)
            except (trio.BrokenResourceError, trio.ClosedResourceError):
                await self._abort_web_socket()
                raise ConnectionClosed(self._close_reason) from None 
开发者ID:HyperionGray,项目名称:trio-websocket,代码行数:20,代码来源:_impl.py

示例4: protocol_send

# 需要导入模块: import trio [as 别名]
# 或者: from trio import ClosedResourceError [as 别名]
def protocol_send(self, event: Event) -> None:
        if isinstance(event, RawData):
            async with self.send_lock:
                try:
                    with trio.CancelScope() as cancel_scope:
                        cancel_scope.shield = True
                        await self.stream.send_all(event.data)
                except (trio.BrokenResourceError, trio.ClosedResourceError):
                    await self.protocol.handle(Closed())
        elif isinstance(event, Closed):
            await self._close()
            await self.protocol.handle(Closed())
        elif isinstance(event, Updated):
            pass  # Triggers the keep alive timeout update
        await self._update_keep_alive_timeout() 
开发者ID:pgjones,项目名称:hypercorn,代码行数:17,代码来源:tcp_server.py

示例5: _read_data

# 需要导入模块: import trio [as 别名]
# 或者: from trio import ClosedResourceError [as 别名]
def _read_data(self) -> None:
        while True:
            try:
                data = await self.stream.receive_some(MAX_RECV)
            except (trio.ClosedResourceError, trio.BrokenResourceError):
                await self.protocol.handle(Closed())
                break
            else:
                if data == b"":
                    await self._update_keep_alive_timeout()
                    break
                await self.protocol.handle(RawData(data))
                await self._update_keep_alive_timeout() 
开发者ID:pgjones,项目名称:hypercorn,代码行数:15,代码来源:tcp_server.py

示例6: _close

# 需要导入模块: import trio [as 别名]
# 或者: from trio import ClosedResourceError [as 别名]
def _close(self) -> None:
        try:
            await self.stream.send_eof()
        except (
            trio.BrokenResourceError,
            AttributeError,
            trio.BusyResourceError,
            trio.ClosedResourceError,
        ):
            # They're already gone, nothing to do
            # Or it is a SSL stream
            pass
        await self.stream.aclose() 
开发者ID:pgjones,项目名称:hypercorn,代码行数:15,代码来源:tcp_server.py

示例7: _send

# 需要导入模块: import trio [as 别名]
# 或者: from trio import ClosedResourceError [as 别名]
def _send(self, data):
        async with self._stream_lock:
            try:
                await self._stream.send_all(data)
            except (trio.BrokenResourceError, trio.ClosedResourceError):
                self._closed = True 
开发者ID:rethinkdb,项目名称:rethinkdb-python,代码行数:8,代码来源:net_trio.py

示例8: _read_until

# 需要导入模块: import trio [as 别名]
# 或者: from trio import ClosedResourceError [as 别名]
def _read_until(self, delimiter):
        """ Naive implementation of reading until a delimiter. """
        buffer = bytearray()

        try:
            while True:
                data = await self._stream.receive_some(1)
                buffer.append(data[0])
                if data == delimiter:
                    break
        except (trio.BrokenResourceError, trio.ClosedResourceError):
            self._closed = True

        return bytes(buffer) 
开发者ID:rethinkdb,项目名称:rethinkdb-python,代码行数:16,代码来源:net_trio.py

示例9: _read_exactly

# 需要导入模块: import trio [as 别名]
# 或者: from trio import ClosedResourceError [as 别名]
def _read_exactly(self, num):
        data = b''
        try:
            while len(data) < num:
                data += await self._stream.receive_some(num - len(data))
            return data
        except (trio.BrokenResourceError, trio.ClosedResourceError):
            self._closed = True 
开发者ID:rethinkdb,项目名称:rethinkdb-python,代码行数:10,代码来源:net_trio.py

示例10: close

# 需要导入模块: import trio [as 别名]
# 或者: from trio import ClosedResourceError [as 别名]
def close(self, noreply_wait=False, token=None, exception=None):
        self._closing = True
        if exception is not None:
            err_message = "Connection is closed (%s)." % str(exception)
        else:
            err_message = "Connection is closed."

        # Cursors may remove themselves when errored, so copy a list of them
        for cursor in list(self._cursor_cache.values()):
            cursor._error(err_message)

        for _, future in self._user_queries.values():
            if not future.done():
                future.set_exception(ReqlDriverError(err_message))

        self._user_queries = {}
        self._cursor_cache = {}

        if noreply_wait:
            noreply = Query(P_QUERY.NOREPLY_WAIT, token, None, None)
            await self.run_query(noreply, False)

        try:
            await self._stream.aclose()
        except (trio.ClosedResourceError, trio.BrokenResourceError):
            pass
        # We must not wait for the _reader_task if we got an exception, because that
        # means that we were called from it. Waiting would lead to a deadlock.
        if self._reader_ended_event:
            await self._reader_ended_event.wait()

        return None 
开发者ID:rethinkdb,项目名称:rethinkdb-python,代码行数:34,代码来源:net_trio.py

示例11: acquire

# 需要导入模块: import trio [as 别名]
# 或者: from trio import ClosedResourceError [as 别名]
def acquire(self, force_fresh=False):
        """
        Raises:
            BackendConnectionError
            trio.ClosedResourceError: if used after having being closed
        """
        async with self._lock:
            transport = None
            if not force_fresh:
                try:
                    # Fifo style to retrieve oldest first
                    transport = self._transports.pop(0)
                except IndexError:
                    pass

            if not transport:
                if self._closed:
                    raise trio.ClosedResourceError()

                transport = await self._connect_cb()

            try:
                yield transport

            except TransportClosedByPeer:
                raise

            except Exception:
                await transport.aclose()
                raise

            else:
                self._transports.append(transport) 
开发者ID:Scille,项目名称:parsec-cloud,代码行数:35,代码来源:transport.py

示例12: test_backend_closed_cmds

# 需要导入模块: import trio [as 别名]
# 或者: from trio import ClosedResourceError [as 别名]
def test_backend_closed_cmds(running_backend):
    async with apiv1_backend_administration_cmds_factory(
        running_backend.addr, running_backend.backend.config.administration_token
    ) as cmds:
        pass
    with pytest.raises(trio.ClosedResourceError):
        await cmds.ping() 
开发者ID:Scille,项目名称:parsec-cloud,代码行数:9,代码来源:test_apiv1_administration_cmds.py

示例13: test_backend_closed_cmds

# 需要导入模块: import trio [as 别名]
# 或者: from trio import ClosedResourceError [as 别名]
def test_backend_closed_cmds(running_backend, alice):
    async with apiv1_backend_authenticated_cmds_factory(
        alice.organization_addr, alice.device_id, alice.signing_key
    ) as cmds:
        pass
    with pytest.raises(trio.ClosedResourceError):
        await cmds.ping() 
开发者ID:Scille,项目名称:parsec-cloud,代码行数:9,代码来源:test_apiv1_authenticated_cmds.py

示例14: test_backend_closed_cmds

# 需要导入模块: import trio [as 别名]
# 或者: from trio import ClosedResourceError [as 别名]
def test_backend_closed_cmds(running_backend, invitation_addr):
    async with backend_invited_cmds_factory(invitation_addr) as cmds:
        pass
    with pytest.raises(trio.ClosedResourceError):
        await cmds.ping() 
开发者ID:Scille,项目名称:parsec-cloud,代码行数:7,代码来源:test_invited_cmds.py

示例15: test_backend_closed_cmds

# 需要导入模块: import trio [as 别名]
# 或者: from trio import ClosedResourceError [as 别名]
def test_backend_closed_cmds(running_backend, alice):
    async with backend_authenticated_cmds_factory(
        alice.organization_addr, alice.device_id, alice.signing_key
    ) as cmds:
        pass
    with pytest.raises(trio.ClosedResourceError):
        await cmds.ping() 
开发者ID:Scille,项目名称:parsec-cloud,代码行数:9,代码来源:test_authenticated_cmds.py


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