My code seems to hang on this popen call
command = "ls"
commandList = shlex.split(command)
print("Executing " + command +"\n")
print(commandList)
output = "#" * 10 + "\n" + server.name + "\n\n"
process = subprocess.Popen(
command,
shell=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
output = process.communicate()[0]
#scriptRunner.threadComplete(output)
return output
The code is in the executeScriptOverSSH method on the SshWorker
class WorkerThread(threading.Thread):
def __init__(self, pathToScript, server, runner):
super(WorkerThread, self).__init__()
self.scriptRunner = runner
self.server = server
self.pathToScript = pathToScript
self.sshWorker = SshWorker.SshWorker()
def run(self):
print('Thread Starting')
output = self.sshWorker.executeScriptOverSSH(
self.server,
self.pathToScript)
print('Thread Finishing!')
self.scriptRunner.threadComplete(output)`
The threads never get past the call to Popen — I’ve checked by using print statements there. Any ideas?
I’ve run the below code and it runs correctly. You mentioned that “check_output barfs if the return code is non zero”, check out the check_output docs it raises a CalledProcessError exception which you can catch and contains all the error details in a nice structure.
The code above follows the same structure you posted in your question. But I don’t recommend you take this approach here are some suggestions:
simple fabric remote run example