def __exit__(self, *args):
"""
Sleeps for a variable amount of time (dependent on when it was last
called), to give a consistent frame rate. If it cannot meet the desired
frame rate (i.e. too much time has occurred since the last call), then
it simply exits without blocking.
"""
self.called += 1
self.total_transit_time += monotonic() - self.enter_time
if self.max_sleep_time >= 0:
elapsed = monotonic() - self.last_time
sleep_for = self.max_sleep_time - elapsed
if sleep_for > 0:
time.sleep(sleep_for)
self.last_time = monotonic()
评论列表
文章目录