yuzhibott 最近的时间轴更新
yuzhibott

yuzhibott

V2EX 第 249367 号会员,加入于 2017-08-18 09:26:34 +08:00
yuzhibott 最近回复了
@lesmiserables0 不能这么骗别人的 23333
@shibingsw 多个定时任务啊,每个定时不一样,join 不是只能一个一个线程执行么
num = 0

def test1(*data):
global num
i = data[0]
while True:
if num == 10:
num = 0
break
print(i)
num += 1
time.sleep(2)

def test2(*data):
i = data[0]
threading.Thread(target=test1, args=(i,)).start()
print("done")

pool = multiprocessing.Pool(processes=5)
for j in range(2):
pool.apply_async(test2, (j,))
大概代码如上,不能用 join(),因为实际中是多任务定时处理,每个任务时间不一样
num = 0

def test1(*data):
global num
i = data[0]
while True:
if num == 10:
num = 0
break
print(i)
num += 1
time.sleep(2)

def test2(*data):
i = data[0]
threading.Thread(target=test1, args=(i,)).start()
print("done")

pool = multiprocessing.Pool(processes=5)
for j in range(2):
pool.apply_async(test2, (j,))
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2702 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 17ms · UTC 15:34 · PVG 23:34 · LAX 08:34 · JFK 11:34
Developed with CodeLauncher
♥ Do have faith in what you're doing.