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.

Source Distribution

aioimport-0.1.5.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

aioimport-0.1.5-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file aioimport-0.1.5.tar.gz.

File metadata

  • Download URL: aioimport-0.1.5.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.8.1 Windows/10

File hashes

Hashes for aioimport-0.1.5.tar.gz
Algorithm Hash digest
SHA256 0eb26f5a0d37545ad5ec803d5bf55d386964a61a0dfdf212a4e784e24b934e54
MD5 1298a9147ab7726e688083a1e75acf12
BLAKE2b-256 ca2751f576a70873310a7fa307a6caf7b26e6a25e85f12b4bd09a22f31c98f30

See more details on using hashes here.

File details

Details for the file aioimport-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: aioimport-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.8.1 Windows/10

File hashes

Hashes for aioimport-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 39add0230e265123d0d674f2d694b2463d13c0ced182b0a1927e1662ddf88b9d
MD5 a98450cfc7e245510569a6eb0db526b3
BLAKE2b-256 5345fffa0f2c3cfeba283ad1026060f4a894f46b9586c39e709987deac66e9fd

See more details on using hashes here.

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