我想知道如何以这样的方式调用外部程序,以便在Python程序运行时允许用户继续与我的程序的UI(使用tkinter构建,如果它很重要)进行交互。程序等待用户选择要复制的文件,因此在外部程序运行时,它们仍应能够选择和复制文件。外部程序是Adobe Flash Player。在Python中同时运行外部程序
也许一些困难是由于我有一个线程“工人”类的事实?它在复制时更新进度条。即使Flash Player处于打开状态,我也希望更新进度条。
我试过
subprocess
模块。该程序运行,但它阻止用户在Flash Player关闭之前使用UI。此外,复制仍然似乎发生在后台,只是在Flash Player关闭之前进度条才会更新。def run_clip(): flash_filepath = "C:\\path\\to\\file.exe" # halts UI until flash player is closed... subprocess.call([flash_filepath])
接着,我尝试使用
concurrent.futures
模块(我是使用Python 3反正)。由于我仍然使用subprocess
来调用应用程序,因此这段代码的行为与上面的例子完全相同并不奇怪。def run_clip(): with futures.ProcessPoolExecutor() as executor: flash_filepath = "C:\\path\\to\\file.exe" executor.submit(subprocess.call(animate_filepath))
请问问题出在哪里使用subprocess
?如果是这样,有没有更好的方法来调用外部程序?提前致谢。
太好了,'child = subprocess.Popen'确实有效。我必须更熟悉模块的方法,但感谢使用'wait'的信息。 – gary 2012-02-14 16:27:13