Subprocess readline() output blocked in toolkit app

In my sgtk toolkit app, I execute a subprocess command that takes several minutes to run. In my GUI, I’d like to display the output so the user knows something is happening. I have a working prototype, but when I put the code into my Shotgun toolkit app, it blocks the output until it’s done. Can’t figure out why…

def run_command(self, command):
    process = subprocess.Popen(command, stdout=subprocess.PIPE)
    while process.poll() is None:
        line = process.stdout.readline()
        output_line = line.strip()
        self.status.setText(output_line)
        QtGui.QApplication.processEvents()
    return_code = process.poll()
    return return_code

Even without the two widget status update lines, I am unable to get it to write to the log file until the command has finished. Any idea how to unblock the output, so I can display the lines in my widget…?

Thanks for any help,
Rich

1 Like