My server runs a Bottle application. One request (/start in following code) starts a subprocess with Popen. The call is non-blocking (other requests can be served during the execution of this subprocess), however, the response to the original request is only received when the subprocess is over (if no other request was received, if another request has been served, the response to the original request is never sent). I don't understand.
Here is my test code :
@route('/start', method=['GET'])
def start():
dateStart = datetime.strftime(datetime.today(), "%Y-%m-%d %H:%M:%S")
cmd = ['python2.7', 'testdate.py']
process = subprocess.Popen(cmd)
return {'success':True, 'dateStart':dateStart, 'dateStop':datetime.strftime(datetime.today(), "%Y-%m-%d %H:%M:%S")}
Result:
- testdate.py writes the current date every second 10 times in a file. I get : 13:58:04 13:58:05 .......... 13:58:13
- The response is received 10s after the request was sent with : {"dateStart": "13:58:03", "dateStop": "13:58:03", "success": true}
- So the response is prepared as soon as the subprocess is started but not sent???? Can anyone explain this to me? Thank you!