Asychronous execution *with* return codes?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • utabintarbo

    #1

    Asychronous execution *with* return codes?

    I hope I have not overlooked a solution already posted, but I seem to
    be unable to suss out a way to achieve both multiple console-less
    executions of a given (console) application and gathering the return
    code from the application.

    What I have found:
    <code>
    import subprocess

    # gives back return code, but does not run asynchronously
    retcode = subprocess.call ([app, lstArgs])
    retcode = subprocess.Pope n([app] + lstArgs).wait()
    # runs the app async, but only returns the pid (no return code)
    pid = subprocess.Pope n([app] + lstArgs).pid
    </code>

    Is there some magic elixir which will get me both?

    TIA

  • MonkeeSage

    #2
    Re: Asychronous execution *with* return codes?

    utabintarbo wrote:
    pid = subprocess.Pope n([app] + lstArgs).pid
    Check out the poll() method and the returncode attribute:


    Regards,
    Jordan

    Comment

    • utabintarbo

      #3
      Re: Asychronous execution *with* return codes?


      MonkeeSage wrote:
      utabintarbo wrote:
      pid = subprocess.Pope n([app] + lstArgs).pid
      >
      Check out the poll() method and the returncode attribute:

      >
      Thanks for the reply.

      If I understand your meaning, I should do something like this (given I
      wish to run an app against several arguments [my use case]):

      for lstArgs in pileOflstArgs:
      uniqueProcessID = subprocess.Pope n([app] + lstArgs)
      pid = uniqueProcessID .pid
      retcode = uniqueProcessID .poll()
      # increment uniqueProcessID
      ....

      If so, how do I handle the poll() on long-running processes? Run a
      bunch and then start a check loop? Am I asking too many questions?

      Comment

      • Justin

        #4
        Re: Asychronous execution *with* return codes?

        If you're on a POSIX system, you could use the usual fork/exec/wait:

        import os
        for lstArgs in pileOflstArgs:
        pid = os.fork()
        if not pid:
        os.execv( app, lstArgs )

        for i in range(len(pileO flstArgs)):
        pid, status = os.wait()

        Of couse, os.wait() will block until a child exits. Look at the docs
        for the status code it returns, though, as it's not just the return
        value of the process.

        On Oct 5, 7:43 am, "utabintarb o" <utabinta...@gm ail.comwrote:
        MonkeeSage wrote:
        utabintarbo wrote:
        pid = subprocess.Pope n([app] + lstArgs).pid
        >
        Check out the poll() method and the returncode attribute:
        http://docs.python.org/lib/node533.htmlThanks for the reply.
        >
        If I understand your meaning, I should do something like this (given I
        wish to run an app against several arguments [my use case]):
        >
        for lstArgs in pileOflstArgs:
        uniqueProcessID = subprocess.Pope n([app] + lstArgs)
        pid = uniqueProcessID .pid
        retcode = uniqueProcessID .poll()
        # increment uniqueProcessID
        ....
        >
        If so, how do I handle the poll() on long-running processes? Run a
        bunch and then start a check loop? Am I asking too many questions?

        Comment

        • utabintarbo

          #5
          Re: Asychronous execution *with* return codes?


          Justin wrote:
          If you're on a POSIX system, you could use the usual fork/exec/wait:
          >
          Sorry. Win32. We are only allowed spoons - no sharp objects. :-P

          Comment

          • Gabriel Genellina

            #6
            Re: Asychronous execution *with* return codes?

            At Thursday 5/10/2006 09:33, utabintarbo wrote:
            ># gives back return code, but does not run asynchronously
            >retcode = subprocess.call ([app, lstArgs])
            >retcode = subprocess.Pope n([app] + lstArgs).wait()
            ># runs the app async, but only returns the pid (no return code)
            >pid = subprocess.Pope n([app] + lstArgs).pid
            ></code>
            >
            >Is there some magic elixir which will get me both?
            Use the async way, and then, os.waitpid()



            Gabriel Genellina
            Softlab SRL





            _______________ _______________ _______________ _____
            Preguntá. Respondé. Descubrí.
            Todo lo que querías saber, y lo que ni imaginabas,
            está en Yahoo! Respuestas (Beta).
            ¡Probalo ya!


            Comment

            • Lawrence D'Oliveiro

              #7
              Re: Asychronous execution *with* return codes?

              In message <1160071806.019 770.198470@e3g2 000cwe.googlegr oups.com>,
              utabintarbo wrote:
              Justin wrote:
              >If you're on a POSIX system, you could use the usual fork/exec/wait:
              >>
              Sorry. Win32. We are only allowed spoons - no sharp objects. :-P
              How about installing Cygwin, then, and running under that?

              Comment

              • Fredrik Lundh

                #8
                Re: Asychronous execution *with* return codes?

                utabintarbo wrote:
                If so, how do I handle the poll() on long-running processes? Run a
                bunch and then start a check loop?
                or use a thread to keep track of each external process.

                </F>


                Comment

                • utabintarbo

                  #9
                  Re: Asychronous execution *with* return codes?


                  Fredrik Lundh wrote:
                  utabintarbo wrote:
                  >
                  If so, how do I handle the poll() on long-running processes? Run a
                  bunch and then start a check loop?
                  >
                  or use a thread to keep track of each external process.
                  >
                  </F>
                  This sounds most promising. Might you have a code snippet (or link to
                  same) illustrating this?

                  Comment

                  Working...