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


Python typing.AsyncIterable方法代码示例

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


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

示例1: to_async_iterable

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncIterable [as 别名]
def to_async_iterable(
        self, maxsize: int, return_index: bool
    ) -> tp.AsyncIterable[T]:

        # build stages first to verify reuse
        main_queue: IterableQueue[pypeln_utils.Element] = IterableQueue(
            maxsize=maxsize, total_sources=1,
        )

        built = {}

        workers: tp.List[Worker] = list(self.build(built, main_queue, main_queue))
        supervisor = Supervisor(workers=workers, main_queue=main_queue)

        async with supervisor:
            async for elem in main_queue:
                if return_index:
                    yield elem
                else:
                    yield elem.value 
开发者ID:cgarciae,项目名称:pypeln,代码行数:22,代码来源:stage.py

示例2: test_subclassing_async_generator

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncIterable [as 别名]
def test_subclassing_async_generator(self):
        class G(typing.AsyncGenerator[int, int]):
            def asend(self, value):
                pass
            def athrow(self, typ, val=None, tb=None):
                pass

        ns = {}
        exec('async def g(): yield 0', globals(), ns)
        g = ns['g']
        self.assertIsSubclass(G, typing.AsyncGenerator)
        self.assertIsSubclass(G, typing.AsyncIterable)
        self.assertIsSubclass(G, collections.AsyncGenerator)
        self.assertIsSubclass(G, collections.AsyncIterable)
        self.assertNotIsSubclass(type(g), G)

        instance = G()
        self.assertIsInstance(instance, typing.AsyncGenerator)
        self.assertIsInstance(instance, typing.AsyncIterable)
        self.assertIsInstance(instance, collections.AsyncGenerator)
        self.assertIsInstance(instance, collections.AsyncIterable)
        self.assertNotIsInstance(type(g), G)
        self.assertNotIsInstance(g, G) 
开发者ID:ShikyoKira,项目名称:Project-New-Reign---Nemesis-Main,代码行数:25,代码来源:test_typing.py

示例3: get_async_response

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncIterable [as 别名]
def get_async_response(self, data: dict, batch_size: int) -> AsyncIterable:
        """Helper function for sending requests asynchronously if the API endpoint does not support batching

        Args:
            data: data to be passed to the API endpoint
            batch_size: requests count

        Yields:
            requests results parsed as json
        """
        loop = asyncio.get_event_loop()
        futures = [
            loop.run_in_executor(
                None,
                requests.post,
                self.url,
                None,
                {k: v[i] for k, v in data.items()}
            )
            for i in range(batch_size)
        ]
        for r in await asyncio.gather(*futures):
            yield r.json() 
开发者ID:deepmipt,项目名称:DeepPavlov,代码行数:25,代码来源:api_requester.py

示例4: _inner_messages

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncIterable [as 别名]
def _inner_messages(self, ws: websockets.WebSocketClientProtocol) -> AsyncIterable[str]:
        # Terminate the recv() loop as soon as the next message timed out, so the outer loop can reconnect.
        try:
            while True:
                try:
                    msg: str = await asyncio.wait_for(ws.recv(), timeout=self.MESSAGE_TIMEOUT)
                    yield msg
                except asyncio.TimeoutError:
                    try:
                        pong_waiter = await ws.ping()
                        await asyncio.wait_for(pong_waiter, timeout=self.PING_TIMEOUT)
                    except asyncio.TimeoutError:
                        raise
        except asyncio.TimeoutError:
            self.logger().warning("WebSocket ping timed out. Going to reconnect...")
            return
        except ConnectionClosed:
            return
        finally:
            await ws.close() 
开发者ID:CoinAlpha,项目名称:hummingbot,代码行数:22,代码来源:dolomite_api_order_book_data_source.py

示例5: _messages

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncIterable [as 别名]
def _messages(self) -> AsyncIterable[Any]:
        try:
            while True:
                try:
                    raw_msg_str: str = await asyncio.wait_for(self._client.recv(), timeout=self.MESSAGE_TIMEOUT)
                    raw_msg = ujson.loads(raw_msg_str)

                    yield raw_to_response(raw_msg)
                except asyncio.TimeoutError:
                    try:
                        pong_waiter = await self._client.ping()
                        await asyncio.wait_for(pong_waiter, timeout=self.PING_TIMEOUT)
                    except asyncio.TimeoutError:
                        raise
        except asyncio.TimeoutError:
            self.logger().warning("WebSocket ping timed out. Going to reconnect...")
            return
        except ConnectionClosed:
            return
        finally:
            await self.disconnect()

    # emit messages 
开发者ID:CoinAlpha,项目名称:hummingbot,代码行数:25,代码来源:bitcoin_com_websocket.py

示例6: aiter_to_list

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncIterable [as 别名]
def aiter_to_list(aiter: AsyncIterable[T],) -> List[T]:
    return [x async for x in aiter] 
开发者ID:Yelp,项目名称:paasta,代码行数:4,代码来源:async_utils.py

示例7: upload_media

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncIterable [as 别名]
def upload_media(self, data: Union[bytes, AsyncIterable[bytes]],
                           mime_type: Optional[str] = None, filename: Optional[str] = None,
                           size: Optional[int] = None) -> ContentURI:
        """
        Upload a file to the content repository.

        See also: `API reference <https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-media-r0-upload>`__

        Args:
            data: The data to upload.
            mime_type: The MIME type to send with the upload request.
            filename: The filename to send with the upload request.
            size: The file size to send with the upload request.

        Returns:
            The MXC URI to the uploaded file.

        Raises:
            MatrixResponseError: If the response does not contain a ``content_uri`` field.
        """
        if magic and isinstance(data, bytes):
            mime_type = mime_type or magic.from_buffer(data, mime=True)
        headers = {}
        if mime_type:
            headers["Content-Type"] = mime_type
        if size:
            headers["Content-Length"] = str(size)
        query = {}
        if filename:
            query["filename"] = filename
        resp = await self.api.request(Method.POST, MediaPath.upload, content=data,
                                      headers=headers, query_params=query)
        try:
            return resp["content_uri"]
        except KeyError:
            raise MatrixResponseError("`content_uri` not in response.") 
开发者ID:tulir,项目名称:mautrix-python,代码行数:38,代码来源:media_repository.py

示例8: from_async_iterable

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncIterable [as 别名]
def from_async_iterable(iterable: AsyncIterable[T]) -> AsyncObservable[T]:
    """Convert an async iterable to a source stream.

    2 - xs = from_async_iterable(async_iterable)

    Returns the source stream whose elements are pulled from the
    given (async) iterable sequence."""

    return FromAsyncIterable(iterable) 
开发者ID:dbrattli,项目名称:aioreactive,代码行数:11,代码来源:from_async_iterable.py

示例9: to_async_iterable

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncIterable [as 别名]
def to_async_iterable(source: AsyncObservable) -> AsyncIterable:
    """Skip the specified number of values.

    Keyword arguments:
    count -- The number of elements to skip before returning the
        remaining values.

    Returns a source stream that contains the values that occur
    after the specified index in the input source stream.
    """

    return ToAsyncIterable(source) 
开发者ID:dbrattli,项目名称:aioreactive,代码行数:14,代码来源:to_async_iterable.py

示例10: repeat

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncIterable [as 别名]
def repeat(value, times=None) -> AsyncIterable:
    for value in itertools.repeat(value, times):
        yield value 
开发者ID:dbrattli,项目名称:aioreactive,代码行数:5,代码来源:iterable.py

示例11: range

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncIterable [as 别名]
def range(*args) -> AsyncIterable:
    for value in builtins.range(*args):
        yield value 
开发者ID:dbrattli,项目名称:aioreactive,代码行数:5,代码来源:iterable.py

示例12: filter

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncIterable [as 别名]
def filter(predicate, source: AsyncIterable) -> AsyncIterable:
    async for value in source:
        if predicate(value):
            yield value 
开发者ID:dbrattli,项目名称:aioreactive,代码行数:6,代码来源:iterable.py

示例13: __init__

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncIterable [as 别名]
def __init__(self, source: AsyncIterable) -> None:
        self._source = source 
开发者ID:dbrattli,项目名称:aioreactive,代码行数:4,代码来源:to_async_observable.py

示例14: to_async_observable

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncIterable [as 别名]
def to_async_observable(source: AsyncIterable) -> AsyncObservable:
    """Convert to async observable.

    Keyword arguments:
    source -- Async iterable to convert to async observable.

    Returns async observable"""

    return ToAsyncObservable(source) 
开发者ID:dbrattli,项目名称:aioreactive,代码行数:11,代码来源:to_async_observable.py

示例15: to_async_iterable

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncIterable [as 别名]
def to_async_iterable() -> Callable[[AsyncObservable], AsyncIterable]:
        from aioreactive.operators.to_async_iterable import to_async_iterable
        return partial(to_async_iterable) 
开发者ID:dbrattli,项目名称:aioreactive,代码行数:5,代码来源:operators.py


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