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. Advertising

  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. Advertising

  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. Advertising

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:
    12,642
    Allan Herriman
    Apr 8, 2004
  2. bienwell
    Replies:
    4
    Views:
    3,860
    bienwell
    May 27, 2005
  3. Marc Carter

    subprocess and non-blocking IO (again)

    Marc Carter, Oct 10, 2005, in forum: Python
    Replies:
    4
    Views:
    987
    Thomas Bellman
    Oct 11, 2005
  4. placid
    Replies:
    8
    Views:
    1,367
    Durumdara
    Aug 4, 2006
  5. nukleus
    Replies:
    14
    Views:
    848
    Chris Uppal
    Jan 22, 2007
Loading...

Share This Page