Created
October 28, 2014 19:46
-
-
Save mredar/26c9bcc9b2df0e6d62fa to your computer and use it in GitHub Desktop.
Delay decorator for "nicing" server downloads
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import time | |
def pause_2b_nice(func): | |
'''Pause the execution for however long func took to run. | |
Useful for not overloading servers when downloading assets. | |
''' | |
def inner(*args, **kwargs): | |
dt_start = dt_end = datetime.datetime.now() | |
ret = func(*args, **kwargs) | |
dt_end = datetime.datetime.now() | |
#print('DELAY:{}'.format((dt_end-dt_start).total_seconds())) | |
time.sleep((dt_end-dt_start).total_seconds()) | |
return ret | |
return inner | |
delay_decorator = pause_2b_nice |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment