[Python-ideas] Fwd: Yielding from the command line
Martin Teichmann
lkb.teichmann at gmail.com
Wed Sep 17 09:59:53 CEST 2014
Hi Andrew, Hi List,
> [ some discussion about calling yield from from the command line skipped ]
>
> I would love to see this. I'm not sure if I'd love it in practice or not, but until
> someone implements it and I can play with it I'm not sure how I'd become sure.
>
> So... You just volunteered, right? Go build it and put it on PyPI, I want it and
> I'll be your best friend forever and ever no takebacks if you do it. :)
Well, so I did, I wrote an IPython extension that does it and put it up on
https://github.com/tecki/ipython-yf
It's more a mock-up of how it should actually look like, but it is a
functioning mock-up.
So now you can write on the command line stuff like:
>>> %load_ext yf
>>> from asyncio import sleep, async
>>> def f():
... yield from sleep(3)
... print("done")
>>> yield from f()
#[wait three seconds]
done
>>> async(f())
>>> #[wait three seconds, or type other commands] done
So as you see, the event loop runs while you are typing commands,
and while they are executed.
Greetings
Martin
More information about the Python-ideas
mailing list