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


Python asyncio.events方法代码示例

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


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

示例1: register

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import events [as 别名]
def register(self, fileobj, events, data=None):
        """
        Register a file object or a :class:`~asynctest.FileMock`.

        If a real selector object has been supplied to the
        :class:`~asynctest.TestSelector` object and ``fileobj`` is not
        a :class:`~asynctest.FileMock` or a :class:`~asynctest.FileDescriptor`
        returned by :meth:`FileMock.fileno()`, the object will be registered to
        the real selector.

        See :meth:`selectors.BaseSelector.register`.
        """
        if isfilemock(fileobj) or self._selector is None:
            key = super().register(fileobj, events, data)
        else:
            key = self._selector.register(fileobj, events, data)

        return key 
开发者ID:Martiusweb,项目名称:asynctest,代码行数:20,代码来源:selector.py

示例2: process_decision_events

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import events [as 别名]
def process_decision_events(self, decision_events: DecisionEvents):
        self.decision_context.set_replaying(decision_events.replay)
        self.decision_context.set_replay_current_time_milliseconds(decision_events.replay_current_time_milliseconds)

        self.handle_decision_task_started(decision_events)
        for event in decision_events.markers:
            if not event.marker_recorded_event_attributes.marker_name == LOCAL_ACTIVITY_MARKER_NAME:
                self.process_event(event);
        for event in decision_events.events:
            self.process_event(event)
        if self.completed:
            return
        self.unblock_all()
        self.event_loop.run_event_loop_once()
        if decision_events.replay:
            self.notify_decision_sent()
        for event in decision_events.decision_events:
            self.process_event(event) 
开发者ID:firdaus,项目名称:cadence-python,代码行数:20,代码来源:decision_loop.py

示例3: _patch_handle

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import events [as 别名]
def _patch_handle():
    """Patch Handle to allow recursive calls."""

    def update_from_context(ctx):
        """Copy context ctx to currently active context."""
        for var in ctx:
            var.set(ctx[var])

    def run(self):
        """
        Run the callback in a sub-context, then copy any sub-context vars
        over to the Handle's context.
        """
        try:
            ctx = self._context.copy()
            ctx.run(self._callback, *self._args)
            if ctx:
                self._context.run(update_from_context, ctx)
        except Exception as exc:
            cb = format_helpers._format_callback_source(
                self._callback, self._args)
            msg = 'Exception in callback {}'.format(cb)
            context = {
                'message': msg,
                'exception': exc,
                'handle': self,
            }
            if self._source_traceback:
                context['source_traceback'] = self._source_traceback
            self._loop.call_exception_handler(context)
        self = None

    if sys.version_info >= (3, 7, 0):
        from asyncio import format_helpers
        events.Handle._run = run 
开发者ID:erdewit,项目名称:nest_asyncio,代码行数:37,代码来源:nest_asyncio.py

示例4: _get_event_loop

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import events [as 别名]
def _get_event_loop():
            current_loop = _get_running_loop()
            if current_loop is not None:
                return current_loop
            return asyncio.events.get_event_loop_policy().get_event_loop() 
开发者ID:open-telemetry,项目名称:opentelemetry-python,代码行数:7,代码来源:aiocontextvarsfix.py

示例5: set_read_ready

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import events [as 别名]
def set_read_ready(fileobj, loop):
    """
    Schedule callbacks registered on ``loop`` as if the selector notified that
    data is ready to be read on ``fileobj``.

    :param fileobj: file object or :class:`~asynctest.FileMock` on which the
                    event is mocked.

    :param loop: :class:`asyncio.SelectorEventLoop` watching for events on
                 ``fileobj``.

    ::

        mock = asynctest.SocketMock()
        mock.recv.return_value = b"Data"

        def read_ready(sock):
            print("received:", sock.recv(1024))

        loop.add_reader(mock, read_ready, mock)

        set_read_ready(mock, loop)

        loop.run_forever() # prints received: b"Data"

    .. versionadded:: 0.4
    """
    # since the selector would notify of events at the beginning of the next
    # iteration, we let this iteration finish before actually scheduling the
    # reader (hence the call_soon)
    loop.call_soon_threadsafe(_set_event_ready, fileobj, loop, selectors.EVENT_READ) 
开发者ID:Martiusweb,项目名称:asynctest,代码行数:33,代码来源:selector.py

示例6: set_write_ready

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import events [as 别名]
def set_write_ready(fileobj, loop):
    """
    Schedule callbacks registered on ``loop`` as if the selector notified that
    data can be written to ``fileobj``.

    :param fileobj: file object or  :class:`~asynctest.FileMock` on which th
        event is mocked.
    :param loop: :class:`asyncio.SelectorEventLoop` watching for events on
        ``fileobj``.

    .. versionadded:: 0.4
    """
    loop.call_soon_threadsafe(_set_event_ready, fileobj, loop, selectors.EVENT_WRITE) 
开发者ID:Martiusweb,项目名称:asynctest,代码行数:15,代码来源:selector.py

示例7: modify

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import events [as 别名]
def modify(self, fileobj, events, data=None):
        """
        Shortcut when calling :meth:`TestSelector.unregister` then
        :meth:`TestSelector.register` to update the registration of a an object
        to the selector.

        See :meth:`selectors.BaseSelector.modify`.
        """
        if isfilemock(fileobj) or self._selector is None:
            key = super().modify(fileobj, events, data)
        else:
            key = self._selector.modify(fileobj, events, data)

        return key 
开发者ID:Martiusweb,项目名称:asynctest,代码行数:16,代码来源:selector.py

示例8: _format_callback

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import events [as 别名]
def _format_callback(handle):
        return asyncio.events._format_callback(handle._callback, handle._args,
                                               None) 
开发者ID:Martiusweb,项目名称:asynctest,代码行数:5,代码来源:selector.py

示例9: _format_event

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import events [as 别名]
def _format_event(event):
    callbacks = []

    if event.events & selectors.EVENT_READ:
        callbacks.append("add_reader({}, {})".format(
            event.fileobj, _format_callback(event.data[0])))

    if event.events & selectors.EVENT_WRITE:
        callbacks.append("add_writer({}, {})".format(
            event.fileobj, _format_callback(event.data[1])))

    return callbacks 
开发者ID:Martiusweb,项目名称:asynctest,代码行数:14,代码来源:selector.py

示例10: fail_on_active_selector_callbacks

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import events [as 别名]
def fail_on_active_selector_callbacks(case):
    ignored_events = case._active_selector_callbacks
    active_events = get_registered_events(case.loop._selector)

    output = ["some events watched during the tests were not removed:"]
    for c in map(_format_event, active_events - ignored_events):
        output.extend(c)

    if len(output) > 1:
        case.fail("\n - ".join(output)) 
开发者ID:Martiusweb,项目名称:asynctest,代码行数:12,代码来源:selector.py

示例11: _get_event_loop

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import events [as 别名]
def _get_event_loop():
                current_loop = _get_running_loop()
                if current_loop is not None:
                    return current_loop
                return asyncio.events.get_event_loop_policy().get_event_loop() 
开发者ID:eventbrite,项目名称:pysoa,代码行数:7,代码来源:compatibility.py

示例12: __init__

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import events [as 别名]
def __init__(self, events: List[HistoryEvent]):
        self.events = peekable(events) 
开发者ID:firdaus,项目名称:cadence-python,代码行数:4,代码来源:decision_loop.py

示例13: has_next

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import events [as 别名]
def has_next(self) -> bool:
        try:
            self.events.peek()
            return True
        except StopIteration:
            return False 
开发者ID:firdaus,项目名称:cadence-python,代码行数:8,代码来源:decision_loop.py

示例14: next

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import events [as 别名]
def next(self) -> Optional[DecisionEvents]:
        events = self.events
        if not self.has_next():
            return None
        decision_events: List[HistoryEvent] = []
        new_events: List[HistoryEvent] = []
        replay = True
        next_decision_event_id = -1
        # noinspection PyUnusedLocal
        event: HistoryEvent
        for event in events:
            event_type = event.event_type
            if event_type == EventType.DecisionTaskStarted or not self.has_next():
                replay_current_time_milliseconds = nano_to_milli(event.timestamp)
                if not self.has_next():
                    replay = False
                    next_decision_event_id = event.event_id + 2
                    break
                peeked: HistoryEvent = events.peek()
                peeked_type = peeked.event_type
                if peeked_type == EventType.DecisionTaskTimedOut or peeked_type == EventType.DecisionTaskFailed:
                    continue
                elif peeked_type == EventType.DecisionTaskCompleted:
                    next(events)
                    next_decision_event_id = peeked.event_id + 1
                    break
                else:
                    raise Exception(
                        "Unexpected event after DecisionTaskStarted: {}".format(peeked))
            new_events.append(event)
        while self.has_next():
            if not is_decision_event(events.peek()):
                break
            decision_events.append(next(events))
        result = DecisionEvents(new_events, decision_events, replay,
                                replay_current_time_milliseconds, next_decision_event_id)
        logger.debug("HistoryHelper next=%s", result)
        return result 
开发者ID:firdaus,项目名称:cadence-python,代码行数:40,代码来源:decision_loop.py

示例15: decide

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import events [as 别名]
def decide(self, events: List[HistoryEvent]):
        helper = HistoryHelper(events)
        while helper.has_next():
            decision_events = helper.next()
            self.process_decision_events(decision_events)
        return self.get_decisions() 
开发者ID:firdaus,项目名称:cadence-python,代码行数:8,代码来源:decision_loop.py


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