throttle.py 文件源码

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

项目:MKFQ 作者: maojingios 项目源码 文件源码
def AddTransfer(self, throttle_name, token_count):
    """Add a count to the amount this thread has transferred.

    Each time a thread transfers some data, it should call this method to
    note the amount sent. The counts may be rotated if sufficient time
    has passed since the last rotation.

    Args:
      throttle_name: The name of the throttle to add to.
      token_count: The number to add to the throttle counter.
    """
    self.VerifyThrottleName(throttle_name)
    transferred = self.transferred[throttle_name]
    try:
      transferred[id(threading.currentThread())] += token_count
    except KeyError:
      thread = threading.currentThread()
      raise ThreadNotRegisteredError(
          'Unregistered thread accessing throttled datastore stub: id = %s\n'
          'name = %s' % (id(thread), thread.getName()))


    if self.last_rotate[throttle_name] + self.ROTATE_PERIOD < self.get_time():
      self._RotateCounts(throttle_name)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号