当我使用multiprocessing.P的apply_async()func时,我看不到要调用的任何子进程

2024-09-29 22:32:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我知道关于池的多处理的基本用法,我使用apply_async()func来避免阻塞,我的问题代码如下:

from multiprocessing import Pool, Queue
import time

q = Queue(maxsize=20)
script = "my_path/my_exec_file"

def initQueue():
   ...

def test_func(queue):
    print 'Coming'
    While True:
     do_sth
    ...

if __name__ == '__main__':
    initQueue()
    pool = Pool(processes=3)
    for i in xrange(11,20):
        result = pool.apply_async(test_func, (q,))
    pool.close()
    while True:
        if q.empty():
            print 'Queue is emty,quit'
            break
        print 'Main Process Lintening'
        time.sleep(2)

输出的结果总是主要的过程,我可以;我找不到“来”这个词。。 上面的代码没有语法错误,也没有任何异常。 任何人都可以帮忙,谢谢


Tags: 代码testimporttrueasynctimequeuemy

热门问题