好的,我说有这段代码:
import time
def helloworld(sleep_time):
while True:
time.sleep(sleep_time)
print('Hello world!')
def hellocountry():
while True:
time.sleep(60)
print('Hello country!')
if __name__ == '__main__':
with Pool(3) as p:
p.map(helloworld, [1, 5, 7])
当helloworld被执行时,我将如何执行hellocountry?我想我可以编写一个包装函数,但这看起来很笨拙和unpythonic。
答案 0 :(得分:1)
只需使用apply_async
方法。
if __name__ == '__main__':
with Pool(3) as p:
p.apply_async(hellocountry)
p.map(helloworld, [1, 5, 7])