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