3
在heroku上运行单个测试仪时,threading
模块是否工作? 如:我可以在单个heroku(python)dyno中运行多个线程吗?
import threading
import time
import random
def foo(x, s):
time.sleep(s)
print ("%s %s %s" % (threading.current_thread(), x, s))
for x in range(4):
threading.Thread(target=foo, args=(x, random.random())).start()
应该返回类似...
$ python3 mythread.py
<Thread(Thread-3, started 123145318068224)> 2 0.27166873449907303
<Thread(Thread-4, started 123145323323392)> 3 0.5510182055055494
<Thread(Thread-1, started 123145307557888)> 0 0.642366815814484
<Thread(Thread-2, started 123145312813056)> 1 0.8985126103340428
是吗?