Skip to main content

Simple asynchronous execution pool primitive for Python 3.6+

Project description

Expool

EO principles respected here Build Status codecov

Simple asynchronous execution pool primitive. You can think of it as of a threading.ThreadPool for coroutines.

Usage

import asyncio
from expool import ExecutionPoolSimple

async def main():
    pool = ExecutionPoolSimple(size=3) # size parameter sets the max amount of concurrent coroutines 
    
    async def some_job():
        await asyncio.sleep(3)
    
    await pool.add(some_job) # Returns immediately if the pool is not full.
    await pool.add(some_job) # If the pool max size is reached, waits 
    # until one of the pool's coroutines finishes.
    
    await pool.close()  # wait for all of the jobs to finish.

You may also set a timeout for .close() method:

    await pool.close(timeout=10)  

If the timeout is reached, ExecutionPoolSimple cancels all remaining coroutines and returns.

You may also want to check out ExecutionPool decorators:

  • ExecutionPoolMonitored - a pool with periodical logging of the jobs inside the pool;
  • ExecutionPoolCapped - a pool with a limited lifespan.

Installation

pip install expool

Project details


Download files

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

Source Distribution

expool-0.1.1.tar.gz (4.3 kB view hashes)

Uploaded Source

Built Distribution

expool-0.1.1-py3-none-any.whl (6.1 kB view hashes)

Uploaded Python 3

Supported by

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