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


Python Event.stop方法代码示例

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


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

示例1: after

# 需要导入模块: from threading import Event [as 别名]
# 或者: from threading.Event import stop [as 别名]
def after(delay, action, *args):
    """
    Execute an action after a given number of seconds.

    This function is executed in a separate thread.

    Parameters
    ----------
    delay : float
        Number of seconds to delay the action.
    action
        To be taken after the interval.
    args : tuple, default is ()
        Arguments for the action.

    Returns
    -------
    Event
        A timer object that can be terminated using the `stop()` method.
    """
    event = Event()

    def wait():
        if event.wait(delay):
            return
        action(*args)

    Thread(target=wait).start()
    event.stop = event.set

    return event
开发者ID:Peque,项目名称:osbrain,代码行数:33,代码来源:common.py

示例2: repeat

# 需要导入模块: from threading import Event [as 别名]
# 或者: from threading.Event import stop [as 别名]
def repeat(interval, action, *args):
    """
    Repeat an action forever after a given number of seconds.

    If a sequence of events takes longer to run than the time available
    before the next event, the repeater will simply fall behind.

    This function is executed in a separate thread.

    Parameters
    ----------
    interval : float
        Number of seconds between executions.
    action
        To be taken after the interval.
    args : tuple, default is ()
        Arguments for the action.

    Returns
    -------
    Event
        A timer object that can be terminated using the `stop()` method.
    """
    event = Event()

    def loop():
        starttime = time.time()
        while True:
            nexttime = starttime + interval
            action(*args)
            after_action = time.time()
            if event.wait(nexttime - after_action):
                break
            starttime = max(after_action, nexttime)

    Thread(target=loop).start()
    event.stop = event.set

    return event
开发者ID:Peque,项目名称:osbrain,代码行数:41,代码来源:common.py


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