Proccess termination

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

    #1

    Proccess termination

    I use popen.popen2 or popen.popen3 to start a new process and read from
    it's stdout/ write to it's stdin.
    But I need a way to know when a process terminates. If it closes it's
    stdin/stdout, it doesn't mean it has really terminated...
    And if possible, I would like to see an exception thrown when that
    happens..
    Do you know about a library that provides these tools other then the
    standard os module... or should I use it otherwise?

    Thanx Alex Rait.

  • Diez B. Roggisch

    #2
    Re: Proccess termination

    alexrait1 wrote:
    [color=blue]
    > I use popen.popen2 or popen.popen3 to start a new process and read from
    > it's stdout/ write to it's stdin.
    > But I need a way to know when a process terminates. If it closes it's
    > stdin/stdout, it doesn't mean it has really terminated...[/color]

    You can use the Popen-objects pid to see if a process still runs.
    [color=blue]
    > And if possible, I would like to see an exception thrown when that
    > happens..[/color]

    Not possible - that exception would be asynchronous to your program flow.
    The only thing I can think of that would make this possible is to have a
    second thread waiting for process termination - and sending the own process
    a signal. If I'm not mistaken, that will be propagated to the main thread.

    All this is meant to be running on unix - not sure how thinks work out on
    windows.

    --
    Regards,

    Diez B. Roggisch

    Comment

    • George Yoshida

      #3
      Re: Proccess termination

      alexrait1 wrote:[color=blue]
      > I use popen.popen2 or popen.popen3 to start a new process and read from
      > it's stdout/ write to it's stdin.
      > But I need a way to know when a process terminates.[/color]
      [color=blue]
      > Do you know about a library that provides these tools other then the
      > standard os module... or should I use it otherwise?[/color]

      popen2.Popen3, popen2.Popen4 and subprosess.Pope n have poll/wait methods.

      These will do what you're looking for.

      --
      George

      Comment

      Working...