threads.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:fandango 作者: tango-controls 项目源码 文件源码
def timed_range(seconds,period,event=None):
    """
    Method used to execute the content of a for loop at periodic intervals.
    For X seconds, this method will return each period fragment.
    event can be used to pass a threading.Event to abort the loop if needed.

    Usage:

      for t in trange(15,0.1): 
        method_executed_at_10Hz_for_15s()
    """
    t0 = time.time()
    diff = 0
    e = event or threading.Event()
    while diff<seconds and not e.is_set():
      e.wait(period)
      diff = time.time()-t0
      if not e.is_set:
        yield diff
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号