【发布时间】:2010-09-25 04:05:45
【问题描述】:
我有一些 Python 代码在我使用 python.exe 运行时可以正常工作,但如果我使用 pythonw.exe 会失败。
def runStuff(命令行): outputFileName = 'somefile.txt' 输出文件 = 打开(输出文件名,“w”) 尝试: 结果 = subprocess.call(commandLine, shell=True, stdout=outputFile) 除了: print '抛出异常:', str(sys.exc_info()[1]) myThread = threading.Thread(None, target=runStuff, commandLine=['whatever...']) myThread.start()我得到的信息是:
抛出异常:[错误 6] 句柄无效但是,如果我不指定 'stdout' 参数,subprocess.call() 启动正常。
我可以看到 pythonw.exe 可能正在重定向输出本身,但我不明白为什么我无法为新线程指定 stdout。
【问题讨论】:
标签: python multithreading subprocess