[IPython-dev] Asyncio extensions for IPython
Damián Avila
damianavila at gmail.com
Tue Sep 30 13:16:54 EDT 2014
Wow... really nice... and I agree on Thomas suggestion.
cheers.
Damian
2014-09-30 14:06 GMT-03:00 Thomas Kluyver <takowl at gmail.com>:
> Hi Martin,
>
> Thanks, that's a fascinating extension. It's impressively little code to
> do something quite complex. I'm also glad to see someone making use of the
> ast_transformers hook.
>
> I noticed you've put it under a GPL license. Much of this ecosystem is
> BSD, so that means your code couldn't ever be integrated into a project
> like IPython. Of course the license is your choice, and I know people feel
> strongly about this, but if you would ever consider relicensing it, it's
> much easier to do that now than years down the line when you have to
> contact every contributor.
>
> Thanks,
> Thomas
>
> On 30 September 2014 07:53, Martin Teichmann <lkb.teichmann at gmail.com>
> wrote:
>
>> Hi,
>>
>> I've been working with the Python 3.4 asyncio package, which
>> uses the yield from statement to perform asynchronous I/O.
>>
>> I realized that such an approach might also be useful for IPython,
>> as it allows to start tasks in the background without stopping the
>> currently running event loop, and without using threads. So I wrote
>> an asyncio extension for IPython. It allows to use the yield from
>> statement at the command line.
>>
>> The important difference to normal commands is, that while they are
>> executed the currently running event loop continues, which is most
>> visible if you are running something like matplotlib. So, while the
>> I/O stuff is running "in the background", the matplotlib Qt window is
>> still responsive.
>>
>> To give an example (don't forget you need python 3.4)
>>
>> In [1]: %load_ext yf # this is my extension
>> In [2]: from asyncio import sleep, async
>> In [3]: def f():
>> ...: yield from sleep(3)
>> ...: print("done")
>> ...: return "returned"
>> In [4]: yield from f()
>> #[wait three seconds]
>> done
>> Out[4]: 'returned'
>> In [5]: async(f())
>> Out[5]: Task(<f>)<PENDING>
>> In [6]: #[wait three seconds, or type other commands] done
>>
>> this is a trivial example which just sleeps, but the point is, it could do
>> anything else, especially I/O, and still the GUI would be responsive.
>>
>> I put this extension onto github as
>>
>> https://github.com/tecki/ipython-yf
>>
>> Greetings
>>
>> Martin
>> _______________________________________________
>> IPython-dev mailing list
>> IPython-dev at scipy.org
>> http://mail.scipy.org/mailman/listinfo/ipython-dev
>>
>
>
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev
>
>
--
*Damián*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20140930/cb5fc729/attachment.html>
More information about the IPython-dev
mailing list