0

I've seen write-ups but am not sure how to apply this to my example. I want to be able to push a button on my webpage, run a piece of python code -- and within the python code it runs another process (executable). The executable takes time, so I want the webpage to not wait until the executable is done running.

I have seen things on daemon and forks, but am not sure how to implement them. I am running an Apache Server with Python CGI on a Windows 8 machine.

Currently, my python code runs and the executable runs fine, but the web page waits until the exe is done processing before updating with an alert window that the "Request has been submitted". Here is my popen code as it is now:

p = subprocess.Popen(['test_sendemail.exe',cmd],shell=False,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)  

Again, everything works fine here, but I need the python script to end even though the exe is running so that it can update the webpage and move on. (once the exe is done running, it fires an email off with results -- which is why I don't want to wait on the webpage for it to finish).

Any thoughts? Thanks!

Community
  • 1
  • 1
mcfly
  • 1,151
  • 4
  • 33
  • 55
  • can you post your python code completely? subprocess.Popen will not wait for your executable to complete unless you have used p.communicate() or p.wait() – venpa Mar 21 '14 at 17:51
  • I don't want it to wait -- that's the purpose. I have tried p.communicate() and p.wait() but all situations have me wait until the executable is done. I want to push the button, invoke the exe, then immediately alert the webpage that the exe has been run. however, in the background on my server I would like the exe to run without any more input from the site or hanging the site. – mcfly Mar 21 '14 at 18:21
  • related: [Popen waiting for child process even when the immediate child has terminated](http://stackoverflow.com/q/13243807/4279) – jfs Mar 21 '14 at 18:25
  • This unfortunately still waits for my exe to stop running – mcfly Mar 21 '14 at 18:36
  • try to start `sendmail` process from an intermediate process created with `CREATE_NEW_PROCESS_GROUP`: `cgi script -> new process group -> sendmail`. Try `close_fds=True` instead of `stdout=PIPE`, etc – jfs Mar 22 '14 at 05:46

0 Answers0