Giter Site home page Giter Site logo

h0rn3t / aio-executor Goto Github PK

View Code? Open in Web Editor NEW

This project forked from miguelgrinberg/aio-executor

0.0 1.0 0.0 13 KB

A concurrent.futures.Executor implementation that runs asynchronous tasks in an asyncio loop.

License: MIT License

Python 100.00%

aio-executor's Introduction

aio-executor

Build Status

A concurrent.futures.Executor implementation that runs asynchronous tasks in an asyncio loop.

Example usage:

from aio_executor import AioExecutor

async def my_async_function(arg):
    # ...

with AioExecutor() as aioexec:
    # single invocation
    f = aioexec.submit(my_async_function, 'foo')
    result = f.result()

    # multiple concurrent invocations using "map"
    results = aioexec.map(my_async_function, ['foo', 'bar', 'baz'])

As a convenience, a run_with_asyncio decorator is also provided. This decorator runs the decorated async function in a AioExecutor instance.

The example below shows how to implement an async view function for the Flask framework using this decorator:

@app.route('/')
@run_with_asyncio
async def index():
    return await get_random_quote()

How to Install

pip install aio-executor

Other Implementations

The idea of implementing an Executor instance based on asyncio is apparently not that original. I initially attempted to register this package on PyPI as "asyncio-executor" and found that the name was already taken.

Below is the list of fairly similar implementations I know about. If for any reason my version does not work for you, be sure to try these others out.

aio-executor's People

Contributors

miguelgrinberg avatar

Watchers

 avatar

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.