Second try: non-blocking subprocess pipe and Tkinter in 2.7

Discussion in 'Python' started by Kevin Walzer, Dec 21, 2012.

  1. Kevin Walzer

    Kevin Walzer Guest

    Yesterday I posted a question about keeping a Tkinter GUI during a
    long-running process, i.e. reading data from a pipe via the subprocess
    module. I think that question did not quite get at the heart of the
    issue because it assumed that Python, like Tcl which underlies Tkinter,
    supports non-blocking, asynchronous reading out of the box. Apparently
    it does not.

    So, my question is hereby revised as such: how can I implement a
    non-blocking read of a subprocess pipe that can write data to the
    Tkinter text widget in an manner that does not cause the GUI to lock up?

    --Kevin
    --
    Kevin Walzer
    Code by Kevin
    http://www.codebykevin.com
     
    Kevin Walzer, Dec 21, 2012
    #1
    1. Advertisements

  2. Kevin Walzer

    Peter Otten Guest

    Kevin Walzer wrote:

    > Yesterday I posted a question about keeping a Tkinter GUI during a
    > long-running process, i.e. reading data from a pipe via the subprocess
    > module. I think that question did not quite get at the heart of the
    > issue because it assumed that Python, like Tcl which underlies Tkinter,
    > supports non-blocking, asynchronous reading out of the box. Apparently
    > it does not.
    >
    > So, my question is hereby revised as such: how can I implement a
    > non-blocking read of a subprocess pipe that can write data to the
    > Tkinter text widget in an manner that does not cause the GUI to lock up?


    You could do blocking reads in a separate thread and use a queue to
    communicate with the GUI in the main thread:

    http://effbot.org/zone/tkinter-threads.htm
     
    Peter Otten, Dec 21, 2012
    #2
    1. Advertisements

  3. Kevin Walzer

    Terry Reedy Guest

    On 12/21/2012 10:52 AM, Kevin Walzer wrote:
    > Yesterday I posted a question about keeping a Tkinter GUI during a
    > long-running process, i.e. reading data from a pipe via the subprocess
    > module. I think that question did not quite get at the heart of the
    > issue because it assumed that Python, like Tcl which underlies Tkinter,
    > supports non-blocking, asynchronous reading out of the box. Apparently
    > it does not.


    There is currently the asyncore module, but I don't know that anyone
    really likes it.

    > So, my question is hereby revised as such: how can I implement a
    > non-blocking read of a subprocess pipe that can write data to the
    > Tkinter text widget in an manner that does not cause the GUI to lock up?


    Interesting question. Guido is currently, with help from many others
    with async experience, working on a replacement for asyncore.
    PEP 3156 - Asynchronous IO Support Rebooted
    http://python.org/dev/peps/pep-3156/

    You can read the pep if you want, but it includes a generalized event
    loop interface. The prototype (partial) implementation includes (or
    will) a default event loop. However, the intention is that it can be
    replaced by (or maybe work with) adapters for existing event loops,
    including that of gui frameworks. Being able write a tk loop adapter and
    easily add io events and handlers to work along side with tk key and
    mouse events and write to a widjet should be an interesting test of the
    new framework.

    --
    Terry Jan Reedy
     
    Terry Reedy, Dec 22, 2012
    #3
    1. Advertisements

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. Hendra Gunawan
    Replies:
    1
    Views:
    16,524
    Allan Herriman
    Apr 8, 2004
  2. bienwell
    Replies:
    4
    Views:
    4,106
    bienwell
    May 27, 2005
  3. Andre Kelmanson

    blocking i/o vs. non blocking i/o (performance)

    Andre Kelmanson, Oct 10, 2003, in forum: C Programming
    Replies:
    3
    Views:
    1,255
    Valentin Tihomirov
    Oct 12, 2003
  4. Marc Carter

    subprocess and non-blocking IO (again)

    Marc Carter, Oct 10, 2005, in forum: Python
    Replies:
    4
    Views:
    1,184
    Thomas Bellman
    Oct 11, 2005
  5. placid
    Replies:
    8
    Views:
    1,642
    Durumdara
    Aug 4, 2006
  6. nukleus
    Replies:
    14
    Views:
    1,268
    Chris Uppal
    Jan 22, 2007
  7. Christian
    Replies:
    5
    Views:
    933
    Esmond Pitt
    Dec 2, 2007
  8. Stuart Moore

    pipe - non blocking read? (fork/Win32)

    Stuart Moore, Jul 2, 2003, in forum: Perl Misc
    Replies:
    6
    Views:
    528
    Bryan Castillo
    Jul 7, 2003
Loading...