wait() on Popen4 object from thread?

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

    #1

    wait() on Popen4 object from thread?

    I'm having problems calling the Popen4 object wait() method
    from a thread. The folloing program produces an error on some
    machines (but seems to work on others)

    ------------------------------8<------------------------------
    import time
    import threading
    import popen2

    def monitorThread() :
    while True:
    s = p.fromchild.rea dline()
    if s:
    print s
    else:
    print p.wait()
    watching = False
    break

    watching = True
    p = popen2.Popen4(' mplayer -quiet -slave test.avi')
    threading.Threa d(target=monito rThread).start( )

    while watching:
    time.sleep(0.1)

    ------------------------------8<------------------------------

    Exception in thread Thread-1:
    Traceback (most recent call last):
    File "/usr/lib/python2.4/threading.py", line 442, in __bootstrap
    self.run()
    File "/usr/lib/python2.4/threading.py", line 422, in run
    self.__target(* self.__args, **self.__kwargs )
    File "testit.py" , line 11, in monitorThread
    print p.wait()
    File "/usr/lib/python2.4/popen2.py", line 94, in wait
    pid, sts = os.waitpid(self .pid, 0)
    OSError: [Errno 10] No child processes


    Is it a requirement that the Popen4 object's wait method be
    called from the same thread that created it?

    Why does it work on one machine:

    Python 2.4.2 (#1, May 7 2006, 17:58:05)
    [GCC 3.4.5 (Gentoo 3.4.5-r1, ssp-3.4.5-1.0, pie-8.7.9)] on linux2
    Type "help", "copyright" , "credits" or "license" for more information.

    But not on another:

    Python 2.4.2 (#1, May 7 2006, 17:34:02)
    [GCC 3.4.5 (Gentoo 3.4.5-r1, ssp-3.4.5-1.0, pie-8.7.9)] on linux2
    Type "help", "copyright" , "credits" or "license" for more information.


    --
    Grant Edwards
    grante@visi.com

  • Grant Edwards

    #2
    Re: wait() on Popen4 object from thread?

    On 2006-05-30, Dennis Lee Bieber <wlfraed@ix.net com.com> wrote:[color=blue]
    > On Tue, 30 May 2006 03:01:54 -0000, Grant Edwards <grante@visi.co m>
    > declaimed the following in comp.lang.pytho n:
    >[color=green]
    >> watching = False[/color]
    >
    > You do realize that this is a LOCAL definition, and is NOT the same
    > "watching" your later loop is waiting on...
    >[color=green]
    >> while watching:
    >> time.sleep(0.1)[/color][/color]

    Oops, forgot the global declaration.

    However, the presence/absence of the global affect whether the
    OSError happens or not.

    --
    Grant Edwards grante Yow! Do I hear th'
    at SPINNING of various
    visi.com WHIRRING, ROUND, and WARM
    WHIRLOMATICS?!

    Comment

    • Grant Edwards

      #3
      Re: wait() on Popen4 object from thread?

      On 2006-05-30, Grant Edwards <grante@visi.co m> wrote:

      doesn't
      V[color=blue]
      > However, the presence/absence of the global affect whether the
      > OSError happens or not.[/color]

      --
      Grant Edwards grante Yow! I'm EMOTIONAL
      at now because I have
      visi.com MERCHANDISING CLOUT!!

      Comment

      Working...