popen and a long running process in a wx.python application

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

    #1

    popen and a long running process in a wx.python application

    Hello,

    How can I capture the output of a long runnning process which I open
    with popen() ?
    I tried reading line by line, char by char, but the result always
    comes when the process finishes.
    (I am trying to make a wx.python program that opens some "make ..."
    with popen). How can I receive the output of the program immediatly,
    so that I can show a progressbar in my application ?
    I always get the program's output after it finished executing.
    Is this the right place, or should I post this to wx.python ?

    Thank you in advance.

  • kyosohma@gmail.com

    #2
    Re: popen and a long running process in a wx.python application

    On Jun 26, 10:16 am, Doru Moisa <moisad...@gmai l.comwrote:
    Hello,
    >
    How can I capture the output of a long runnning process which I open
    with popen() ?
    I tried reading line by line, char by char, but the result always
    comes when the process finishes.
    (I am trying to make a wx.python program that opens some "make ..."
    with popen). How can I receive the output of the program immediatly,
    so that I can show a progressbar in my application ?
    I always get the program's output after it finished executing.
    Is this the right place, or should I post this to wx.python ?
    >
    Thank you in advance.
    When talking about anything advanced with wxPython, you usually want
    to submit it to the wxPython user's group. Lots of advanced users
    (including the author of wxPython) answer questions there.

    I would recommend looking at the following link as this will probably
    be one of the first suggestions:


    wxPython mailing list: http://www.wxpython.org/maillist.php

    I used a variation of one of the threading example in the
    LongRunningTask s page to send output to a text widget, through stdout
    redirection.

    Good luck!

    Mike

    Comment

    • Ratko

      #3
      Re: popen and a long running process in a wx.python application

      On Jun 26, 10:16 am, Doru Moisa <moisad...@gmai l.comwrote:
      Hello,
      >
      How can I capture the output of a long runnning process which I open
      with popen() ?
      I tried reading line by line, char by char, but the result always
      comes when the process finishes.
      (I am trying to make a wx.python program that opens some "make ..."
      with popen). How can I receive the output of the program immediatly,
      so that I can show a progressbar in my application ?
      I always get the program's output after it finished executing.
      Is this the right place, or should I post this to wx.python ?
      >
      Thank you in advance.


      I think this is the right list to post this in since it's independent
      of wxPython.
      I just recently went through this and got it working properly. Your
      problem is that the output is buffered and is only flushed upon exit
      (and that's when you read() it)
      Here's a piece of code:

      doRead = True
      p = subprocess.Pope n(["ls"], stdout=sp.PIPE, stderr=sp.STDOU T,
      bufsize=1)
      while doRead:
      txt = os.read(p.stdou t.fileno(), 2048)
      time.sleep(0.5) # read at most x times / sec

      A few things to note:
      (1) you must use os.read and not the builtin read() for unbuffered
      read.
      (2) you probably want to run this while loop in a thread because read
      will block until there's some text available
      (3) this is a polling method where I read at most 2 a second in the
      above example
      (4) this works on Mac, Windows and Linux the same (besides the "ls"
      command of course)
      (5) after you read this text you can send it to a TextCtrl or
      something

      Hope that helps.

      Ratko

      Comment

      • Doru Moisa

        #4
        Re: popen and a long running process in a wx.python application


        Mike, Ratko,

        Thanks a lot guys, for the quick and prompt answers.

        Doru


        Comment

        Working...