V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  yuzhibott  ›  全部回复第 1 页 / 共 1 页
回复总数  6
@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   ·   我们的愿景   ·   实用小工具   ·   3003 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 15ms · UTC 11:07 · PVG 19:07 · LAX 04:07 · JFK 07:07
Developed with CodeLauncher
♥ Do have faith in what you're doing.