I have this strange problem where from my Python code in server1 i am sending a request to server2 where i need to execute a linux command which starts an application(and it starts a process in linux) and then return the command output to calling function in server 1. Snippet of the code is as below. The problem here is the command in server2 executes fine and prints the result also, but it does not execute the 'self.wfile.write(response_str)' command and does not return any value back to the calling code in server1. So code in server1 hangs forever, though the command in server2 executes successfully. I am confused here because, it is not that command is not coming out, the print of the output of the command works fine, but writing back to the post call is not hapenning. I tried executing the same code with commands like 'ps' or 'ls'. It works fine. Only when I start this new process to start the application, it is not working.
Any idea why this is and how to resolve ?? Btw, I am having a very old version of Python here 2.5.2. Any help would be much appreciated.
Calling code in server 1
def startApp(self):
data = urllib.parse.urlencode(request_data).encode("utf-8")
req = urllib.request.Request("http://server_url:8044",data)
response = urllib.request.urlopen(req).read().decode('utf8')
Called code in server 2
def do_POST(self):
............
response_str = commands.getoutput(start_cmd)
print(response_str)
self.wfile.write(response_str)