0

I am trying to use the below code sample to check if a schema file exists, if it does not I start a thread to use Popen to download a new schema file while opening up a second window "Downloading new schema file. Please wait.". Using time.sleep(0.5) to wait for the file to download before closing the second window. This all works fine on Mac OSX, but in windows it opens up the second window "Downloading new schema file. Please wait." but then just freezes without downloading the schema file, I then need to crash it out. As this works on Mac, what can I do to make this work on both OS's please?

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)
speedyrazor
  • 3,127
  • 7
  • 33
  • 51
  • 1
    don't use `PIPE` unless you feed/consume the corresponding pipes. If you need to ignore the output, see [How to hide output of subprocess in Python 2.7](http://stackoverflow.com/q/11269575/4279) – jfs Apr 06 '15 at 23:15
  • It was that easy! Removing all the PIPE commands made it work. Thanks J.F. Sebastian. – speedyrazor Apr 07 '15 at 05:35

0 Answers0