Skip to main content

No project description provided

Project description


# aioexec

aynscio exectuors as simple as it can get.


## Description

Aioexec is a simple, intuitive interface around the `concurrent.futures` package and asyncio's `loop.run_in_executor` method. Aioexec is leightweight, no dependencies and ~70 LOC.


## Requirements

aioexec requires Python `>= 3.6`


## Install

pip install aioexec

or

pipenv install aioexec


## Usage

With asyncio you usually run an executor something like this:

```python
import aysncio
from concurrent.futures import ProcessPoolExecutor

# ...

loop = asyncio.get_event_loop()

foo = await loop.run_in_executor(
ProcessPoolExecutor(1), lambda: my_func(foo='baz')
)
```

With aioexec you would do the same like this:

```python
import aysncio
from aioexec import Procs

# ...

foo = await Procs(1).call(my_func, foo='baz')
```

You can call a batch of functions in the same executor like this:

```python
import asyncio as aio
from aioexec import Procs, Call

my_values = await aio.gather(
*Procs(3).batch(
Call(my_func, foo='1'),
Call(my_func, foo='2'),
Call(my_func, foo='3'),
)
```

This plays nicely with comprehensions:

```python
my_values = await aio.gather(
*Procs(10).batch(
Call(my_func, foo=i) for i in range(0, 10)
)
```

It works the same for Threads:

```python
import asyncio as aio
from aioexec import Threads

foo = await Threads(1).call(my_func, foo='baz')

```

If necessary, you can pass an event loop to the executors like this:

```python
foo = await Threads(1, my_loop).call(my_func, foo='baz')
foo = await Procs(1, my_loop).call(my_func, foo='baz')
```




Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aioexec-0.3.2-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file aioexec-0.3.2-py3-none-any.whl.

File metadata

File hashes

Hashes for aioexec-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5817d889247be649e0636054349b98a17762ff005bf9d657b407a6033e04c967
MD5 47b983326c38f2425a9e342fcba97a7b
BLAKE2b-256 3a5520b851abf8fb37272d02eed24e700a8564aa0b7e98cc622d77ea74a72653

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page