MultiTasking
Turn any Python method into a non-blocking task with a single decorator
Repository Health
Technical Analysis
MultiTasking is a lightweight Python library that converts ordinary methods into asynchronous, non-blocking calls simply by applying a decorator. Instead of wiring up threads or processes by hand, you annotate a function with @multitasking.task and each call runs concurrently in the background.
It is aimed at I/O-bound workloads — API calls, web scraping, and file operations — where you want many operations in flight at once without managing a thread pool yourself. The library supports both threading and multiprocessing engines, configurable concurrency limits, graceful signal handling to stop tasks, and a wait_for_tasks barrier to join everything before continuing.
What You Get
- A
@multitasking.taskdecorator that runs decorated calls concurrently - Selectable execution engines — threading or multiprocessing
- Configurable maximum concurrency via
set_max_threadsand semaphore-backed pools wait_for_tasks()to block until all in-flight tasks finish- Signal helpers (
killall,wait_for_tasks) for graceful Ctrl-C handling
Common Use Cases
- Firing off many I/O-bound API calls concurrently without a manual thread pool
- Parallelizing web-scraping or download loops with one decorator
- Running background file or network operations while the main flow continues
- Adding simple concurrency to a script without adopting asyncio
Under The Hood
Architecture - The whole library is a single module, multitasking/__init__.py. A module-level Config (a TypedDict) holds global state — detected CPU cores, the default engine, max concurrency, daemon flag, and a POOLS registry of PoolConfig entries, each pairing a Semaphore with either a Thread or Process engine. The @task decorator wraps the target function so that calling it acquires a pool slot, spawns a worker on the chosen engine, and tracks it for later joining; wait_for_tasks and killall coordinate shutdown.
Tech Stack - Pure Python built entirely on the standard library — threading (Thread, Semaphore) and multiprocessing (Process, cpu_count), plus functools.wraps and signal integration. It has no third-party runtime dependencies.
Code Quality - Recent versions added complete type hints (using TypedDict for config structures), thorough docstrings, and PEP8-compliant formatting. The code is small and readable, though the project sees infrequent maintenance and ships an example.py rather than an extensive automated test suite.
API Design - The API is about as approachable as concurrency gets: one decorator plus a couple of module-level helpers. The README’s quick-start is a few lines, and sensible defaults (auto-detected cores, thread engine) mean most users never touch configuration, giving it a very low learning curve.