0
我簡化了我想要實現儘可能 我有以下腳本:爲Python線程計算平均睡眠
import time, urllib, random
import threading
def get(timeout):
for i in range(2):
time.sleep(timeout)
return urllib.urlopen('http://localhost:9855').read()
def calculate_timeout(total_threads):
pass
if __name__ == '__main__':
total = random.randint(0,400)
for i in xrange(total):
threading.thread(target=get, kwargs={"timeout":calculate_timeout(len(total)}).start()
我需要做的就是修改這樣的calculate_timeout
功能這樣一來,無論隨機數是多少, 平均每分鐘不會有超過60個urllib請求。