[Python-ideas] How the heck does async/await work in Python 3.5

Andrew Barnert abarnert at yahoo.com
Thu Feb 25 13:42:01 EST 2016


On Feb 25, 2016, at 08:47, Guido van Rossum <guido at python.org> wrote:
> 
> (Of course Tkinter does support network I/O, so it would be possible
> to integrate with that, too. Or some hybrid where you somehow figure
> out how to wait using a Selector *or* tkinter events in the same
> loop.)

I remember that back in the late 90s, you often needed a loop like this pseudocode:

    next_ui = now() + 20ms
    while True:
        livesocks = poll(socks, timeout=next_ui-now())
        for sock in livesocks:
            handle(sock)
        if now() >= next_ui:
            ui_loop_once()
            next_ui = now() + 20ms

The idea is that GUI/audio/video/game code expects to only fire 20-60 times/second, and may do a lot of work each time; network code dealing with dozens of sockets expects to be fired a lot more often, and to do a lot less work each time.

Is this still an issue? If I wanted to write, say, a BitTorrent client like Transmission or uTorrrent using Tkinter, and I fired the Tkinter loop after every selector poll, would it waste too much time checking for events from the OS and onidle handlers and so on thousands of times/second? (And if this is still an issue, is waking 50 times/sec still an acceptable way to solve it, or will you be keeping laptops from sleeping and so on?)

I feel like I must have worked on something over the past decade that would tell me that... but everything I can think of (that didn't use something like Qt to abstract it out), the network stuff goes on a different thread or threads, and communicates with the UI by posting events in one direction and kicking a pipe in the other.



More information about the Python-ideas mailing list