GithubHelp home page GithubHelp logo

gr1n / asyncio-ipython-magic Goto Github PK

View Code? Open in Web Editor NEW
28.0 4.0 2.0 7 KB

An extension for IPython that help to run AsyncIO code in your interactive session

License: MIT License

Python 100.00%
asyncio ipython ipython-magic

asyncio-ipython-magic's Introduction

asyncio-ipython-magic Requirements Status PyPI Supported Python versions

An extension for IPython that help to run AsyncIO code in your interactive session.

Based on Gist.

Installation

Install asyncio-ipython-magic using pip:

$ pip install asyncio-ipython-magic

...or directly from the repository using the %install_ext magic command:

$ In[1]: %install_ext https://raw.githubusercontent.com/Gr1N/asyncio-ipython-magic/master/asynciomagic.py

Enjoy!

Usage

In [1]: %load_ext asynciomagic

In [2]: import asyncio

In [3]: import time

In [4]: async def foo():
   ...:     i = 0
   ...:     while i < 3:
   ...:         print('time =', time.time())
   ...:         i += 1
   ...:         await asyncio.sleep(2)
   ...:

In [5]: %%async_
   ...: await foo()
   ...:
time = 1478985421.307329
time = 1478985423.309606
time = 1478985425.31514

In [6]: %await_ foo()
time = 1487097377.700184
time = 1487097379.705614
time = 1487097381.707186

In [7]:

Testing

It just works, I hope.

License

asyncio-ipython-magic is licensed under the MIT license. See the license file for details.

asyncio-ipython-magic's People

Contributors

gr1n avatar graingert avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

asyncio-ipython-magic's Issues

extension is not ^C-safe

For example:

In [1]: import asyncio
In [2]: l = asyncio.Lock()
In [7]: %await_ l
# OK
In [8]: %await_ l
# waits forever, since lock is already taken, so let's break it:
^C---------------------------------------------------------------------------
KeyboardInterrupt
[backtrace omitted]
KeyboardInterrupt:

In [10]: l.release()
# OK
In [11]: %await_ l
---------------------------------------------------------------------------
RuntimeError
[backtrace omitted]
~/.pyenv/versions/3.6.1/lib/python3.6/asyncio/base_events.py in run_until_complete(self, future)
    462         future.remove_done_callback(_run_until_complete_cb)
    463         if not future.done():
--> 464             raise RuntimeError('Event loop stopped before Future completed.')
    465
    466         return future.result()

RuntimeError: Event loop stopped before Future completed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.