Skip to main content

Asynchronous module import for asyncio

Project description

aioimport

Asynchronous module import for asyncio

Getting Started

Installing

Install from PyPI using:

pip install aioimport

The problem

Some naughty modules have long running operations during import

Naive solution

First thing that comes to mind is make import local:

async def my_work() -> None:
    import naughty  # will block event loop

It reduces time your program takes to start (or library to import), but it is still blocking your event loop.

Usage

import aioimport

async def my_work() -> None:
    await aioimport.import_module("naughty")  # will asynchronously import module
    import naughty  # will be instantaneous since `naughty` is already in `sys.modules`
    await aioimport.reload(naughty)  # and you can asynchronously reload modules too

How it works

Module import is done in asyncio default executor.

Be aware of the fact that GIL still exists and technically import is done concurrently rather than in parallel with your code.

License

This project is licensed under the MIT License - see the LICENSE file for details

Project details


Download files

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

Files for aioimport, version 0.1.5
Filename, size File type Python version Upload date Hashes
Filename, size aioimport-0.1.5-py3-none-any.whl (3.6 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size aioimport-0.1.5.tar.gz (2.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page