1
我开发的一个Python GUI在相同的目录下执行一个exe文件。我需要允许用户打开GUI的多个实例。这会导致同时调用相同的exe并引发以下错误:the process can not access the file because it is being used by another process
。我使用python GUI中的专用线程来运行exe。允许多个Python GUI同时运行相同的exe文件
如何让多个GUI同时运行相同的exe文件?
我将不胜感激代码示例。
以下是主题。运行包括执行exe。这个exe是用fortran编写的。
class LineariseThread(threading.Thread):
def __init__(self, parent):
threading.Thread.__init__(self)
self._parent = parent
def run(self):
self.p = subprocess.Popen([exe_linearise], shell=True, stdout=subprocess.PIPE)
print threading.current_thread()
print "Subprocess started"
while True:
line = self.p.stdout.readline()
if not line:
break
print line.strip()
self._parent.status.SetStatusText(line.strip())
# Publisher().sendMessage(('change_statusbar'), line.strip())
sys.stdout.flush()
if not self.p.poll():
print " process done"
evt_show = LineariseEvent(tgssr_show, -1)
wx.PostEvent(self._parent, evt_show)
def killtree(self, pid):
print pid
parent = psutil.Process(pid)
print "in killtree sub: "
for child in parent.get_children(recursive=True):
child.kill()
parent.kill()
def abort(self):
if self.isAlive():
print "Linearisation thread is alive"
# kill the respective subprocesses
if not self.p.poll():
# stop them all
self.killtree(int(self.p.pid))
self._Thread__stop()
print str(self.getName()) + " could not be terminated"
self._parent.LineariseThread_killed=True
您不显示用于创建子进程的代码,标识exe或文件的名称,因此很难知道为什么它无法执行多个实例。请注意,许多exe文件不允许在任何情况下运行自己的多个实例,但我们无法知道是否属于这种情况,因为您还没有告诉我们它是什么exe文件:-) –
请发送完整的回溯错误。 – User