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


Python typing.AsyncIterator方法代码示例

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


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

示例1: from_annotations

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncIterator [as 别名]
def from_annotations(request_annotation, response_annotation):
        if (hasattr(request_annotation, "__origin__") and
                issubclass(request_annotation.__origin__, collections.abc.AsyncIterator)):
            request_type = request_annotation.__args__[0]
            request_stream = True
        else:
            request_type = request_annotation
            request_stream = False

        if (hasattr(response_annotation, "__origin__") and
                issubclass(response_annotation.__origin__, collections.abc.AsyncIterator)):
            response_type = response_annotation.__args__[0]
            response_stream = True
        else:
            response_type = response_annotation
            response_stream = False
        cardinality = Cardinality.get_cardinality_for(request_stream=request_stream,
                                                      response_stream=response_stream)
        return RPCSignature(cardinality, request_type, response_type) 
开发者ID:standy66,项目名称:purerpc,代码行数:21,代码来源:rpc.py

示例2: predict

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncIterator [as 别名]
def predict(
        self, records: AsyncIterator[Record]
    ) -> AsyncIterator[Record]:
        if not self.model:
            raise ModelNotTrained(
                "Train the model first before getting preictions"
            )
        test_records = await self.get_test_records(records)
        x_test = pd.DataFrame([record.features() for record in test_records])
        predictions = await self.get_predictions(x_test)
        probability = await self.get_probabilities(x_test)
        target = self.parent.config.predict.name
        for record, predict, prob in zip(
            test_records, predictions, probability
        ):
            record.predicted(target, predict, max(prob))
            yield record 
开发者ID:intel,项目名称:dffml,代码行数:19,代码来源:config.py

示例3: predict

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncIterator [as 别名]
def predict(
        self, records: AsyncIterator[Record]
    ) -> AsyncIterator[Tuple[Record, Any, float]]:
        if not self._filepath.is_file():
            raise ModelNotTrained("Train model before prediction.")
        async for record in records:
            record_data = []
            for feature in record.features(self.features).values():
                record_data.extend(
                    [feature] if self.np.isscalar(feature) else feature
                )
            predict = self.np.array([record_data])
            self.logger.debug(
                "Predicted Value of {} for {}: {}".format(
                    self.parent.config.predict,
                    predict,
                    self.clf.predict(predict),
                )
            )
            target = self.parent.config.predict.name
            record.predicted(
                target, self.clf.predict(predict)[0], self.confidence
            )
            yield record 
开发者ID:intel,项目名称:dffml,代码行数:26,代码来源:scikit_base.py

示例4: predict_input_fn

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncIterator [as 别名]
def predict_input_fn(self, records: AsyncIterator[Record], **kwargs):
        """
        Uses the numpy input function with data from record features.
        """
        x_cols: Dict[str, Any] = {feature: [] for feature in self.features}
        ret_records = []
        async for record in records:
            if not record.features(self.features):
                continue
            ret_records.append(record)
            for feature, results in record.features(self.features).items():
                x_cols[feature].append(self.np.array(results))
        for feature in x_cols:
            x_cols[feature] = self.np.array(x_cols[feature])
        self.logger.info("------ Record Data ------")
        self.logger.info("x_cols:    %d", len(list(x_cols.values())[0]))
        self.logger.info("-----------------------")
        input_fn = self.tf.compat.v1.estimator.inputs.numpy_input_fn(
            x_cols, shuffle=False, num_epochs=1, **kwargs
        )
        return input_fn, ret_records 
开发者ID:intel,项目名称:dffml,代码行数:23,代码来源:dnnc.py

示例5: predict

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncIterator [as 别名]
def predict(
        self, records: AsyncIterator[Record]
    ) -> AsyncIterator[Tuple[Record, Any, float]]:
        # Load saved regression line
        regression_line = self.storage.get("regression_line", None)
        # Ensure the model has been trained before we try to make a prediction
        if regression_line is None:
            raise ModelNotTrained("Train model before prediction.")
        # Expand the regression_line into named variables
        m, b, accuracy = regression_line
        # Iterate through each record that needs a prediction
        async for record in records:
            # Grab the x data from the record
            x = record.feature(self.features[0])
            # Calculate y
            y = m * x + b
            # Set the calculated value with the estimated accuracy
            record.predicted(self.config.predict.name, y, accuracy)
            # Yield the record to the caller
            yield record 
开发者ID:intel,项目名称:dffml,代码行数:22,代码来源:slr.py

示例6: records

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncIterator [as 别名]
def records(self) -> AsyncIterator[Record]:
        async for record in self.sctx.records():
            async for ctx, result in self.octx.run(
                [
                    Input(
                        value=record.feature(feature.name),
                        definition=Definition(
                            name=feature.name, primitive=str(feature.dtype())
                        ),
                    )
                    for feature in self.parent.config.features
                ]
            ):
                if result:
                    record.evaluated(result)
                yield record 
开发者ID:intel,项目名称:dffml,代码行数:18,代码来源:df.py

示例7: init_refresh_token

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncIterator [as 别名]
def init_refresh_token(
        base_url: str,
        client_id: str,
        client_secret: str,
        verify_ssl: bool,
        proxy: bool
) -> AsyncIterator[RefreshToken]:
    """Initializes RefreshToken instance and authenticates with CrowdStrike Falcon.

    Args:
        base_url (str): CrowdStrike Falcon Cloud base URL.
        client_id (str): CrowdStrike Falcon application ID.
        client_secret (str): CrowdStrike Falcon application secret.
        verify_ssl (bool): Whether the request should verify the SSL certificate.
        proxy (bool): Whether to run the integration using the system proxy.

    Yields:
        AsyncIterator[RefreshToken]: RefreshToken instance initialized with client details.
    """
    refresh_token = RefreshToken(base_url, client_id, client_secret, verify_ssl, proxy)
    await refresh_token.get_access_token()
    task = create_task(refresh_token.refresh_token_loop())
    yield refresh_token
    task.cancel() 
开发者ID:demisto,项目名称:content,代码行数:26,代码来源:CrowdStrikeFalconStreamingV2.py

示例8: on_dog_added

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncIterator [as 别名]
def on_dog_added(
    parent: typing.Any, args: dict, ctx: dict, info: dict
) -> typing.AsyncIterator[dict]:
    pubsub: PubSub = ctx["pubsub"]
    queue: Queue = Queue()

    @pubsub.on("dog_added")
    def on_dog(dog: Dog) -> None:
        queue.put(dog)

    while True:
        try:
            dog = queue.get_nowait()
        except Empty:
            await asyncio.sleep(0.01)
            continue
        else:
            queue.task_done()
            if dog is None:
                break
            yield {"dogAdded": dog._asdict()} 
开发者ID:tartiflette,项目名称:tartiflette-asgi,代码行数:23,代码来源:resolvers.py

示例9: __aiter__

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncIterator [as 别名]
def __aiter__(self) -> tp.AsyncIterator[T]:

        while not self.is_done():

            if self.namespace.exception:
                exception, trace = await self.exception_queue.get()

                try:
                    exception = exception(f"\n\n{trace}")
                except:
                    exception = Exception(f"\n\nOriginal: {exception}\n\n{trace}")

                raise exception

            x = await self.get()

            if isinstance(x, pypeln_utils.Continue):
                continue
            elif isinstance(x, pypeln_utils.Done):
                self.namespace.remaining -= 1
                continue

            yield x 
开发者ID:cgarciae,项目名称:pypeln,代码行数:25,代码来源:queue.py

示例10: rtm

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncIterator [as 别名]
def rtm(
        self, url: Optional[str] = None, bot_id: Optional[str] = None
    ) -> AsyncIterator[events.Event]:
        """
        Iterate over event from the RTM API

        Args:
            url: Websocket connection url
            bot_id: Connecting bot ID

        Returns:
            :class:`slack.events.Event` or :class:`slack.events.Message`

        """
        while True:
            bot_id = bot_id or await self._find_bot_id()
            url = url or await self._find_rtm_url()
            async for event in self._incoming_from_rtm(url, bot_id):
                yield event
            url = None 
开发者ID:pyslackers,项目名称:slack-sansio,代码行数:22,代码来源:abc.py

示例11: _incoming_from_rtm

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncIterator [as 别名]
def _incoming_from_rtm(
        self, url: str, bot_id: str
    ) -> AsyncIterator[events.Event]:
        """
        Connect and discard incoming RTM event if necessary.

        :param url: Websocket url
        :param bot_id: Bot ID
        :return: Incoming events
        """
        async for data in self._rtm(url):
            event = events.Event.from_rtm(json.loads(data))
            if sansio.need_reconnect(event):
                break
            elif sansio.discard_event(event, bot_id):
                continue
            else:
                yield event 
开发者ID:pyslackers,项目名称:slack-sansio,代码行数:20,代码来源:abc.py

示例12: mock_request_response

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncIterator [as 别名]
def mock_request_response(request_type: Type[BaseEvent],
                                response: BaseEvent,
                                event_bus: EndpointAPI) -> AsyncIterator[None]:
    ready = asyncio.Event()
    task = asyncio.ensure_future(_do_mock_response(request_type, response, event_bus, ready))
    await ready.wait()
    try:
        yield
    finally:
        if not task.done():
            task.cancel()

        try:
            await task
        except asyncio.CancelledError:
            pass 
开发者ID:ethereum,项目名称:trinity,代码行数:18,代码来源:event_bus.py

示例13: timeRangeAsync

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncIterator [as 别名]
def timeRangeAsync(
        start: Union[time_, datetime],
        end: Union[time_, datetime],
        step: float) -> AsyncIterator[datetime]:
    """Async version of :meth:`timeRange`."""
    assert step > 0
    delta = timedelta(seconds=step)
    t = _fillDate(start)
    tz = timezone.utc if t.tzinfo else None
    now = datetime.now(tz)
    while t < now:
        t += delta
    while t <= _fillDate(end):
        await waitUntilAsync(t)
        yield t
        t += delta 
开发者ID:erdewit,项目名称:ib_insync,代码行数:18,代码来源:util.py

示例14: iter

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncIterator [as 别名]
def iter(self, offs: int) -> AsyncIterator[Any]:
        '''
        Returns an iterator of change entries in the log
        '''
        if not self.donexslog:
            return

        if self.isfini:
            raise s_exc.IsFini()

        maxoffs = offs

        for item in self._nexuslog.iter(offs):
            if self.isfini:
                raise s_exc.IsFini()
            maxoffs = item[0] + 1
            yield item

        async with self.getChangeDist(maxoffs) as dist:
            async for item in dist:
                if self.isfini:
                    raise s_exc.IsFini()
                yield item 
开发者ID:vertexproject,项目名称:synapse,代码行数:25,代码来源:nexus.py

示例15: getCortexAndProxy

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncIterator [as 别名]
def getCortexAndProxy(self) -> AsyncIterator[Tuple[Any, Any]]:
        with syntest.getTestDir(startdir=self.tmpdir) as dirn:

            s_tools_backup.backup(self.testdata.dirn, dirn, compact=False)

            async with await s_cortex.Cortex.anit(dirn, conf=self.coreconfig) as core:
                assert not core.inaugural

                lockmemory = self.coreconfig.get('layers:lockmemory', False)
                logedits = self.coreconfig.get('layers:logedits', True)

                await core.view.layers[0].layrinfo.set('lockmemory', lockmemory)
                await core.view.layers[0].layrinfo.set('logedits', logedits)

            async with await s_cortex.Cortex.anit(dirn, conf=self.coreconfig) as core:
                async with core.getLocalProxy() as prox:
                    if lockmemory:
                        await core.view.layers[0].layrslab.lockdoneevent.wait()

                    await s_lmdbslab.Slab.syncLoopOnce()

                    yield core, prox 
开发者ID:vertexproject,项目名称:synapse,代码行数:24,代码来源:benchmark_cortex.py


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