Keep a python script running after browser window closed

Discussion in 'Python' started by sophie_newbie, Mar 7, 2008.

  1. Hi,

    I have a cgi script that performs a very long computation that can
    take several hours to complete. Is there any smart way that I can keep
    this script running until it is finished (after the user has closed
    the browser) and email them with the results. The email bit isn't the
    problem, I just don't know how to keep the code running in the
    background. I'm sure there is a smart way to do this...

    Thanks!
     
    sophie_newbie, Mar 7, 2008
    #1
    1. Advertising

  2. On Mar 7, 10:28 am, sophie_newbie <> wrote:
    > Hi,
    >
    > I have a cgi script that performs a very long computation that can
    > take several hours to complete. Is there any smart way that I can keep
    > this script running until it is finished (after the user has closed
    > the browser) and email them with the results. The email bit isn't the
    > problem, I just don't know how to keep the code running in the
    > background. I'm sure there is a smart way to do this...
    >
    > Thanks!


    You might have your cgi script use the subprocess module to open a
    second script that does the long-running process.

    Mike
     
    Mike Driscoll, Mar 7, 2008
    #2
    1. Advertising

  3. On Mar 7, 4:33 pm, Mike Driscoll <> wrote:
    > On Mar 7, 10:28 am, sophie_newbie <> wrote:
    >
    > > Hi,

    >
    > > I have a cgi script that performs a very long computation that can
    > > take several hours to complete. Is there any smart way that I can keep
    > > this script running until it is finished (after the user has closed
    > > the browser) and email them with the results. The email bit isn't the
    > > problem, I just don't know how to keep the code running in the
    > > background. I'm sure there is a smart way to do this...

    >
    > > Thanks!

    >
    > You might have your cgi script use the subprocess module to open a
    > second script that does the long-running process.
    >
    > Mike


    Ya it looks like:

    import subprocess

    # spawn subprocess
    subprocess.Popen(["python", "spawn.py"])

    Should do this job, where spawn.py is the script to do the job.
    Thanks.
     
    sophie_newbie, Mar 10, 2008
    #3
  4. sophie_newbie

    Guest

    On Mar 10, 1:42 pm, sophie_newbie <> wrote:
    > On Mar 7, 4:33 pm, Mike Driscoll <> wrote:
    >
    >
    >
    > > On Mar 7, 10:28 am, sophie_newbie <> wrote:

    >
    > > > Hi,

    >
    > > > I have a cgi script that performs a very long computation that can
    > > > take several hours to complete. Is there any smart way that I can keep
    > > > this script running until it is finished (after the user has closed
    > > > the browser) and email them with the results. The email bit isn't the
    > > > problem, I just don't know how to keep the code running in the
    > > > background. I'm sure there is a smart way to do this...

    >
    > > > Thanks!

    >
    > > You might have your cgi script use the subprocess module to open a
    > > second script that does the long-running process.

    >
    > > Mike

    >
    > Ya it looks like:
    >
    > import subprocess
    >
    > # spawn subprocess
    > subprocess.Popen(["python", "spawn.py"])
    >
    > Should do this job, where spawn.py is the script to do the job.
    > Thanks.


    In real life, you probably want spawn.py to do a full daemonize. That
    means fork/setsid/fork/chdir appropriately/deal with stdin/stdout/
    umask, or however you set up a service on Windows.
     
    , Mar 10, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?R2FyeQ==?=
    Replies:
    1
    Views:
    511
    =?Utf-8?B?R2FyeQ==?=
    Nov 11, 2005
  2. Replies:
    1
    Views:
    631
    Hans Kesting
    Sep 19, 2008
  3. Matt Kruse
    Replies:
    5
    Views:
    311
    Richard Cornford
    Sep 9, 2003
  4. TM360
    Replies:
    2
    Views:
    197
    TM360
    Jun 30, 2005
  5. hisan
    Replies:
    1
    Views:
    1,337
    Dan Stromberg
    Jun 25, 2012
Loading...

Share This Page