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 nasty modules have long running operations during import
Naive solution
First thing that comes to mind is to postpone import by moving it into the function that need that module:
async def my_work(self) -> None:
import this # will block until imported
It reduces your startup time, but it is still blocking your event loop.
Usage
The preferred way to use aioimport
is:
import aioimport
async def my_work(self) -> None:
await aioimport.import_module("this") # will asynchronously import module
import this # will be instantaneous since `this` is already in `sys.modules`
# and you can asynchronously reload it too:
await aioimport.reload(this)
How it works
Module import is done in new thread worker.
Be aware of the fact that GIL still exists and technically import is done concurrently rather than in parallel with your code.
Future work
Currently after your first use of aioimport
it's workers threads run forever waiting for new imports.
The plan is to have some form of automatic shutdown after some time passes since last import.
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
Built Distribution
Hashes for aioimport-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9654774e1d43e413eb4285f460e67a5409c538784a97a01fe0fba19709da82a2 |
|
MD5 | fbc721c5fce75033ae61bfff5ec4f985 |
|
BLAKE2b-256 | d2048e9fe2a30053ca7d45a44487a55dceaf42d2e5dc466957c0a35a8022feed |