Skip, this repo [1] contains a toy example originally from Dino
Viehland's (@DinoV) talk "Using futures for async GUI programming in
Python 3.3" presented at PyCon US 2013. When I found the example was
broken because of changes in the API of Tulip. It now runs fine with
the asyncio included in Python 3.3.

[1] https://github.com/fluentpython/asyncio-tkinter

Dino's example is not about the exact kind of "linearization" you
mention, but about delegating long running tasks to coroutines so that
the GUI remains responsive -- without resorting to callbacks.

In the script tkapp2.py [2] the three methods do_count_sequentially,
do_count_with_callbacks and do_count (a coroutine) contrast the three
approaches to solving the toy problem of counting words in a long text
file.

[2] https://github.com/fluentpython/asyncio-tkinter/blob/master/tkapp2.py

Cheers,

Luciano

On Fri, May 8, 2015 at 12:30 PM, Skip Montanaro
<[email protected]> wrote:
> Are there examples of using asyncio to "linearize" the logic of GUI
> applications? One problem with the event loop+callback structure of
> many/most/all GUI applications is that the actual "business logic" can get
> torn into pieces. One form submission callback seems to operate
> independently of all others, when in fact, there is an underlying linear
> flow to the way things happen.
>
> While my eventual interest is actually Gtk/Glib and their event loops, I'm
> constrained by use of Python 2.7 at work the moment. In theory, I could try
> using Trollius and GBlub, but GBulb seems to be Python 3.x only. I was
> hoping to experiment with the idea of using asyncio+coroutines+tkinter to
> better expose the logic of a simple application. Does Python 3.4/3.5 provide
> the necessary bits to allow tkinter to interoperate with asyncio? I see a
> closed case on Github: https://github.com/python/asyncio/issues/21 but it's
> not entirely clear that it works or where the actual code which performs the
> necessary magic actually lives. I'm not sure what this is:
>
> https://bitbucket.org/ramalho/asyncio_staging/branches/compare/ramalho/asyncio_staging:default%0Dhaypo/asyncio_staging:default#chg-asyncio_tkinter/talksrc/tkevents.py
>
> though it looks promising.
>
> Thanks,
>
> Skip
>



-- 
Luciano Ramalho
|  Author of Fluent Python (O'Reilly, 2015)
|     http://shop.oreilly.com/product/0636920032519.do
|  Professor em: http://python.pro.br
|  Twitter: @ramalhoorg

Reply via email to