Python concurrent.ThreadPoolExecutor未能等待?

Python concurrent.ThreadPoolExecutor未能等待?,python,multithreading,concurrent.futures,Python,Multithreading,Concurrent.futures,我正在尝试使用concurrent.futures中的ThreadPoolExecutor提高脚本性能。 我正在通过Popen启动一些外部python脚本,并将它们封装为未来的对象,但是这些对象在完成时进入回调函数,但是我可以看到它们在我的机器上运行(它们运行了相当长的时间)。 代码如下所示: with futures.ThreadPoolExecutor(max_workers=4) as executor: p1 = executor.submit(subprocess.P

我正在尝试使用concurrent.futures中的ThreadPoolExecutor提高脚本性能。 我正在通过Popen启动一些外部python脚本,并将它们封装为未来的对象,但是这些对象在完成时进入回调函数,但是我可以看到它们在我的机器上运行(它们运行了相当长的时间)。 代码如下所示:

with futures.ThreadPoolExecutor(max_workers=4) as executor: 
        p1 = executor.submit(subprocess.Popen([myotherPythonscript1], stdout = subprocess.PIPE))
        p1.add_done_callback(process_result)
        p2 = executor.submit(subprocess.Popen([myotherPythonscript2], stdout = subprocess.PIPE))
        p2.add_done_callback(process_result)

def process_result( future ):
        logger.info( "Seeding process finished...")
我还在running()和wait()未来函数中尝试了不同的方法,但结果相同。将来的对象标记为已完成,但实际上它们仍在运行。 我错过什么了吗


谢谢,

您不能只将
Popen
的结果传递给您的执行者,您必须传递一个可调用的

>>> from concurrent.futures import *
>>> from subprocess import *
>>> executor = ThreadPoolExecutor(4)
>>> future = executor.submit(Popen(['echo', 'test'], stdout=PIPE))
>>> future.exception()
TypeError("'Popen' object is not callable",)
另一方面,这是可行的:

from concurrent.futures import *
from subprocess import *

def make_call():
    process = Popen(['echo', 'test'], stdout=PIPE)
    return process.communicate()[0]

executor = ThreadPoolExecutor(4)
future = executor.submit(make_call)
print(future.result())

这部分解决了我的问题。我必须包含一个check_pid子例程以使所有线程同时工作,因为使用communicate()时,Popen正在等待进程完成。非常感谢。