我正在尝试使用下面的代码示例检查架构文件是否存在,如果不存在我启动线程使用Popen下载新架构文件,同时打开第二个窗口“下载新架构文件。请等待。”。在关闭第二个窗口之前,使用time.sleep(0.5)等待文件下载。这一切在Mac OSX上运行正常,但在Windows中它会打开第二个窗口“正在下载新的模式文件。请稍等。”但是然后只是冻结而不下载模式文件,然后我需要将其崩溃。 由于这适用于Mac,我可以做些什么来使这两个操作系统都能正常工作?
def schemaVersionCheck(self, Version):
foundSchemaFile = False
for rngFile in os.listdir("."):
if rngFile.endswith(".rng"):
foundSchemaFile = True
if rngFile != self.schemaFile:
foundSchemaFile = False
if foundSchemaFile == False:
threading.Thread(target=self.getNewSchema, args=(Version, )).start()
msg = "Downloading new schema file. Please wait."
self.busyDlg = wx.BusyInfo(msg)
while not os.path.exists(self.schemaFile):
time.sleep(0.5)
self.busyDlg = None
def getNewSchema(self, Version):
schemaType = "transitional"
self.schemaFile = Version + "-" + schemaType + ".rng"
command = '%s -m generateSchema -u %s -p %s -schema %s -schemaType %s -s shortname -destination .' % (self.params["Link"], self.params["Username"], self.params["Password"], Version, schemaType)
if self.params["systemType"] == "Windows":
command = command + " -WONoPause true"
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
p = Popen(command, startupinfo=startupinfo, shell=False, stdout=PIPE, stderr=PIPE, stdin=PIPE)
else:
p = Popen(shlex.split(command), shell=False, stdout=PIPE, stderr=PIPE, stdin=PIPE)