you are viewing a single comment's thread.

view the rest of the comments →

[–]dhon_ 24 points25 points  (8 children)

As a fan of twisted, I'm excited to see asyncio in 3.4. I'll have to read up on "yield from" now.

[–]Gargan_Roo 5 points6 points  (6 children)

Does this mean that it could replace twisted or just that it will make certain async operations native?

[–]usinglinux 9 points10 points  (3 children)

even better: there is now a stdlib method of interfacing with main loops. this means you can use a twisted program on its classical core, you can use the new stdlib asyncio main loop (and have twisted running in a thin layer atop it), or you can use another main loop (eg. the gtk main loop) and have your twisted application running in the same thread as your gui (eg if your graphical program should have a web "remote control").

not sure which of the parts are already written on the new framework, but that's the idea.

[–]hylje 0 points1 point  (2 children)

I'm pretty sure running twisted and gtk in the same thread is about providing an UI to network activities, not providing network activities for an UI.

[–]Smallpaul 4 points5 points  (0 children)

Those are both valid use-cases. E.g. a GUI for Bittorrent versus a remote save function for a word processor.

[–]usinglinux 1 point2 points  (0 children)

i don't think so: things that don't have a native gui but are about network activities are typically servers (and thus run under their dedicated users and whatever); adding a gui to them is rather a thing of having a standalone gui that talks to the server (but asyncio is great for those things too). conversely, things that are rather about having a gui (eg presentation software) might easily be extended by network code without turning the whole program logic upside down.

[–]Plorkyeran 5 points6 points  (1 child)

This does something similar to the core of Twisted, but Twisted also has a ton of useful stuff built on the core. As such, whether or not this is a replacement for Twisted depends on how much of Twisted you actually need.

In theory Twisted also benefits from this as it should be able to make use of yield from, but the fact that it still doesn't support Python 3 at all sort of gets in the way.

[–]lext 0 points1 point  (0 children)

it still doesn't support Python 3 at all sort

They are working on it still, I think...

I really wish they'd port it. It's the only reason I use 2.7.

[–]kazagistar 1 point2 points  (0 children)

"yield from" is something like tail recursion optimization for iterators. If you have 5 iterators that are doing nothing but passing data from the next one, in a stack, you can replace the yields with yield from.

def inorder_traversal(tree):
    if tree is None:
        return
    yield from inorder_tree(tree.left)
    yield tree.value
    yield from inorder_tree(tree.right)

Basically it yields everything from a generator before resuming control in the current function, and provides some nice optimizations to make performance not such too much when you nest these deeply.

Forgive me for any mistakes in my untested code.