Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Python: asyncio and Tkinter

506 views
Skip to first unread message

c.b...@posteo.jp

unread,
Dec 20, 2017, 8:36:57 AM12/20/17
to
I am looking for an "elegant" and "official" way to use asyncio in
Tkinter applications. The goal is that the GUI is not freezing while
doing some download-tasks (over 100 files from different locations).

I am looking around on the web for solutions but couldn't find one.
Only some workarounds with unknown and possible sideffects.

I asked the same question on StackOverflow with a MWE
<https://stackoverflow.com/q/47895765/4865723>

On my current state I wouuld say there is not an official solution for
this. asyncio and Tkinter are not build to work together without dirty
hacks.

Do you have other informations?

I think about combining asyncio with multithreading so the asyncio
event loop has it's own thread and is not blocking the GUI event loop.
Or using only multithreading.

Chris Angelico

unread,
Dec 20, 2017, 8:43:04 AM12/20/17
to
On Wed, Dec 20, 2017 at 10:42 AM, <c.b...@posteo.jp> wrote:
> I am looking for an "elegant" and "official" way to use asyncio in
> Tkinter applications. The goal is that the GUI is not freezing while
> doing some download-tasks (over 100 files from different locations).
>
> ...
>
> I think about combining asyncio with multithreading so the asyncio
> event loop has it's own thread and is not blocking the GUI event loop.
> Or using only multithreading.

I would recommend threading. You can run your GUI event loop on one
thread, and your network I/O loop on another thread. Both threads
spend the bulk of their time blocked on I/O, and you've limited
yourself to a finite number of threads (as opposed to a pure threaded
approach with every download is run on a separate thread), so resource
consumption should be reasonable.

ChrisA

c.b...@posteo.jp

unread,
Dec 20, 2017, 3:26:46 PM12/20/17
to
X-Post:
<https://mail.python.org/pipermail/tkinter-discuss/2017-December/003927.html>

Dear Chris.

On 2017-12-21 00:42 Chris Angelico <ros...@gmail.com> wrote:
> I would recommend threading. You can run your GUI event loop on one
> thread, and your network I/O loop on another thread.

Thank you very much for your answer. It also came to my mind to
separate each loop in it's own thread. But I am for a way from being a
professional in that topics.

I created a minimal working example to ask that question on
StackOVerflow, too. There is no multithreading in that example.
<https://stackoverflow.com/q/47895765/4865723>

Now I modified that example "based" on your solution. But the GUI is
still freezing why my tasks are working. Your solution is a bit to
complex for me and use some technics (the server think) I don't know.

Could you please throw an eye on the current state of my code?
<https://gitlab.com/snippets/1689797>

Wu Xi

unread,
Dec 30, 2017, 6:47:21 PM12/30/17
to
this is kinda interesting. seems there is no easy way though

Lawrence D’Oliveiro

unread,
Dec 30, 2017, 7:44:19 PM12/30/17
to
On Sunday, December 31, 2017 at 12:47:21 PM UTC+13, Wu Xi wrote:
> this is kinda interesting. seems there is no easy way though

If I could do it for GTK/GLib <https://github.com/ldo/glibcoro>, I don’t see why Tk should be hard. ;)

Wu Xi

unread,
Dec 31, 2017, 7:35:15 PM12/31/17
to
Lawrence D’Oliveiro:
> On Sunday, December 31, 2017 at 12:47:21 PM UTC+13, Wu Xi wrote:
>> this is kinda interesting. seems there is no easy way though
>
> If I could do it for GTK/GLib <https://github.com/ldo/glibcoro>, I don’t see why Tk should be hard. ;)


well, hard or no, but glibcoro is a no workie here. 2-3 chaos, as intended by Guido.

0 new messages