Python CGI - Accepting Input, Invoking Another Process, Ending CGI

Discussion in 'Python' started by LarsenMTL, Nov 3, 2004.

  1. LarsenMTL

    LarsenMTL Guest

    Python Users:

    Based on previous suggestions from this group, I'm attempting to write
    a python CGI that takes input from an HTML form, invokes a second
    python script using this input, tells the user that their process has
    started, ends the cgi output and later emails the results of the
    invoked script.

    My problem is that no mater how I invoke the 2nd script (spawnlp with
    P_NOWAIT, system with &, etc..) the CGI caller continues to run until
    it finishes. If you press the stop button or close the browser
    certain portions of the 2nd script finish but not all of it. In
    paticular the 2nd script uses teTex (invoked by os.system) to process
    some tex files, this always errors out if the browser is closed or
    stopped.

    Regardless of all that, what is the proper way to have a python CGI
    batch another python script?

    Thanks,

    Mark
    LarsenMTL, Nov 3, 2004
    #1
    1. Advertising

  2. > Based on previous suggestions from this group, I'm attempting to write
    > a python CGI that takes input from an HTML form, invokes a second
    > python script using this input, tells the user that their process has
    > started, ends the cgi output and later emails the results of the
    > invoked script.
    >
    > My problem is that no mater how I invoke the 2nd script (spawnlp with
    > P_NOWAIT, system with &, etc..) the CGI caller continues to run until
    > it finishes. If you press the stop button or close the browser
    > certain portions of the 2nd script finish but not all of it. In
    > paticular the 2nd script uses teTex (invoked by os.system) to process
    > some tex files, this always errors out if the browser is closed or
    > stopped.


    Did you try to daemonize your script? That will decouple it from the running
    process, so maybe that helps. In the aspn cookbook there is a good recipe
    for daemonizing.


    --
    Regards,

    Diez B. Roggisch
    Diez B. Roggisch, Nov 3, 2004
    #2
    1. Advertising

  3. LarsenMTL

    Eric Walstad Guest

    LarsenMTL wrote:

    > Python Users:
    >
    > Based on previous suggestions from this group, I'm attempting to write
    > a python CGI that takes input from an HTML form, invokes a second
    > python script using this input, tells the user that their process has
    > started, ends the cgi output and later emails the results of the
    > invoked script.
    >
    > My problem is that no mater how I invoke the 2nd script (spawnlp with
    > P_NOWAIT, system with &, etc..) the CGI caller continues to run until
    > it finishes. If you press the stop button or close the browser
    > certain portions of the 2nd script finish but not all of it. In
    > paticular the 2nd script uses teTex (invoked by os.system) to process
    > some tex files, this always errors out if the browser is closed or
    > stopped.
    >
    > Regardless of all that, what is the proper way to have a python CGI
    > batch another python script?
    >
    > Thanks,
    >
    > Mark


    Hi Mark,

    I had to do something like this in mod_python. I ended up using a
    mod_python function to detach the process from the request. I don't know
    how mod_python handles it, but it worked for me may be a lead for you to
    follow (looking at the mod_python source, that is):
    <http://www.modpython.org/pipermail/mod_python/2004-June/015719.html>

    Best,

    Eric.
    Eric Walstad, Nov 4, 2004
    #3
  4. LarsenMTL

    LarsenMTL Guest

    "Diez B. Roggisch" <> wrote in message news:<cmb3nl$sj4$00$-online.com>...
    > > Based on previous suggestions from this group, I'm attempting to write
    > > a python CGI that takes input from an HTML form, invokes a second
    > > python script using this input, tells the user that their process has
    > > started, ends the cgi output and later emails the results of the
    > > invoked script.
    > >
    > > My problem is that no mater how I invoke the 2nd script (spawnlp with
    > > P_NOWAIT, system with &, etc..) the CGI caller continues to run until
    > > it finishes. If you press the stop button or close the browser
    > > certain portions of the 2nd script finish but not all of it. In
    > > paticular the 2nd script uses teTex (invoked by os.system) to process
    > > some tex files, this always errors out if the browser is closed or
    > > stopped.

    >
    > Did you try to daemonize your script? That will decouple it from the running
    > process, so maybe that helps. In the aspn cookbook there is a good recipe
    > for daemonizing.


    Thanks. I think I got it. Looking at that recipe hinted me at the
    idea that I need to close or redirect stdin, stdout and stderr. Some
    searches around here confirmed that.

    Cheers.
    LarsenMTL, Nov 4, 2004
    #4
  5. LarsenMTL

    Eric Walstad Guest

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    LarsenMTL wrote:

    > "Diez B. Roggisch" <> wrote in message
    > news:<cmb3nl$sj4$00$-online.com>...
    >> > Based on previous suggestions from this group, I'm attempting to write
    >> > a python CGI that takes input from an HTML form, invokes a second
    >> > python script using this input, tells the user that their process has
    >> > started, ends the cgi output and later emails the results of the
    >> > invoked script.
    >> >
    >> > My problem is that no mater how I invoke the 2nd script (spawnlp with
    >> > P_NOWAIT, system with &, etc..) the CGI caller continues to run until
    >> > it finishes. If you press the stop button or close the browser
    >> > certain portions of the 2nd script finish but not all of it. In
    >> > paticular the 2nd script uses teTex (invoked by os.system) to process
    >> > some tex files, this always errors out if the browser is closed or
    >> > stopped.

    >>
    >> Did you try to daemonize your script? That will decouple it from the
    >> running
    >> process, so maybe that helps. In the aspn cookbook there is a good
    >> recipe for daemonizing.

    >
    > Thanks. I think I got it. Looking at that recipe hinted me at the
    > idea that I need to close or redirect stdin, stdout and stderr. Some
    > searches around here confirmed that.
    >
    > Cheers.

    Hi Mark,

    Would you mind posting a snippet of how you solved the problem? I'd
    appreciate seeing what you did.

    Thanks,

    Eric.
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.4 (GNU/Linux)

    iD8DBQFBim4ThlnH2nphKS4RArFhAKDgEBBQvIZjdn39kmcCg2k00opJWgCfTtP0
    E2ByNLFDa4eavr25H5MWZ80=
    =UU+k
    -----END PGP SIGNATURE-----
    Eric Walstad, Nov 4, 2004
    #5
    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. mumebuhi
    Replies:
    1
    Views:
    508
    Dennis Lee Bieber
    Oct 27, 2006
  2. Collin

    Accepting text input

    Collin, May 12, 2008, in forum: Python
    Replies:
    7
    Views:
    276
    Kam-Hung Soh
    May 15, 2008
  3. matt
    Replies:
    6
    Views:
    330
    David Thompson
    Jul 27, 2009
  4. Rob Young

    forking and ending a CGI process

    Rob Young, Aug 11, 2003, in forum: Perl Misc
    Replies:
    1
    Views:
    117
    Gregory Toomey
    Aug 11, 2003
  5. Bill H

    Accepting XML input

    Bill H, Jul 6, 2006, in forum: Perl Misc
    Replies:
    3
    Views:
    94
    Tad McClellan
    Jul 6, 2006
Loading...

Share This Page