Skip to main content

lite-taskman 🚀

English version | 中文版

lite-taskman is an ultra-lightweight (~100 lines of code) thread pool management tool for Python, dedicated to providing a delightful development experience. It is specifically engineered for concurrent refactoring of sequential code, dynamic task incrementation, and real-time progress feedback.

Far from the complexity of the native ThreadPoolExecutor, it supports injecting tasks on the fly and offers an intuitive way to retrieve results, helping you achieve a smooth shift from single-threaded to multi-threaded execution.


✨ Key Features

In concurrent programming, the mental burden of complexity is often the enemy of Python newcomers. lite-taskman condenses powerful functionality into about 100 lines of source code to bring you:

  • A Smooth Refactoring Experience: No need to reconstruct core logic. With simple API replacement, you can elevate legacy sequential code to parallel execution instantly, reaping the performance dividends of concurrency.
  • Intuitive Control: Break free from complex Future object management. Whether you need results in their original order or want to consume them via streaming, the logic is designed to align perfectly with a developer's natural thinking.
  • Delightful Dynamics: As natural as "adding more rice to your bowl while eating." It supports injecting new tasks at any time during execution, making incremental scenarios like web crawling and recursive scanning more elegant than ever.
  • Ultra-lightweight Feedback: Zero dependencies and millisecond-level responsiveness. Combined with real-time progress callbacks, it ensures the status of every task is always under your control.

📦 Installation

pip install lite-taskman

💡 Common Patterns

1. Minimalist Mode: Smooth Shift to Parallel

Leverage multi-core performance by simply changing function calls to add().

# Original sequential logic.
# Total execution time = time(make_soymilk) + time(buy_buns) + time(make_dumplings)
# soymilk = make_soymilk(soy, milk)
# buns = buy_buns(2)
# dumplings = make_dumplings(8, type='pork')

# Transform sequential code into parallel execution with just three lines—ultra-smooth!
from lite_taskman import TaskMan

tman = TaskMan() # Initialize thread pool
tman.add(make_soymilk, soy, milk) # Add task: Simply pass the function as the first argument...
tman.add(buy_buns, 2) # and keep other arguments exactly as they were
tman.add(make_dumplings, 8, type='pork') # Use proprietary parameters for task name, weight, and extra data (see docs)

# exec() returns a result list strictly matching the add() sequence
# Total execution time = max(time(make_soymilk), time(buy_buns), time(make_dumplings))
soymilk, buns, dumplings = [r.result for r in tman.exec()]

2. Incremental Mode: "Add While Running"

Perfect for crawlers: If you discover a new URL while fetching the first page, just add() it immediately.

with TaskMan() as tman:
    tman.add(fetch_url, "http://example.com/page1")
    for r in tman.process():
        # process() is a generator; the loop continues as long as new tasks are added
        new_urls = parse_links(r.result)
        for url in new_urls:
            tman.add(fetch_url, url) # Dynamic addition

3. Pool Reuse

If you have multiple batches of tasks but want to avoid the overhead of repeatedly creating and destroying thread pools, use all().

with TaskMan(max_workers=4) as tman:
    # Batch 1
    tman.add(make_soymilk, soy, milk)
    tman.add(buy_bun, money)
    soymilk, bun = (t.result for t in tman.all()) # Blocks to get results without closing the pool
    
    # Batch 2 (Reuses the 4 existing worker threads)
    for i in range(8): tman.add(make_dumpling, i)
    dumplings = (t.result for t in tman.all()) 

🛠️ API Reference

Core Methods

Method Description Use Case
add(...) Submits a task. Supports custom names, item counts, and extra data. Execution starts immediately. Base for all scenarios.
process() Generator. Yields results in completion order. Supports dynamic add(). Crawlers, recursion, real-time processing.
all() Blocking. Waits for all tasks and returns results sorted by addition order. Batch processing with pool reuse.
exec() Blocking. Equivalent to with + all(). Auto-shuts down the pool after completion. One-off parallel tasks, simplest call.
shutdown() Immediately shuts down the pool and clears the task queue. Manual resource management.

TaskMan.add() Parameters

To avoid naming conflicts, tool-specific parameters are prefixed with _tm_:

  • _tm_name: Task name (defaults to function name) for identification and callbacks.
  • _tm_batch_size: Task weight (i.e., the number of items within a task). E.g., if one page contains 20 records, set this to 20.
  • _tm_extra: Metadata pass-through. Returned as-is in Result.extra.

Progress Callback progress_cb

def my_cb(name, task_done, task_all, batch_done, batch_all, elapsed_sec):
    # name: Current task name
    # task_done/task_all: Progress based on task count
    # batch_done/batch_all: Progress based on workload (batch_size)
    # elapsed_sec(float): Cumulative elapsed time in seconds

📄 License

This project is licensed under the MIT License.

Author: Rocks Wang (rockswang@foxmail.com)

Metadata

Release files for lite-taskman 0.9.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lite-taskman 0.9.1
File Size Uploaded Provenance Actions
lite_taskman-0.9.1.tar.gz 11.2 kB Without provenance Details for lite_taskman-0.9.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lite-taskman 0.9.1
File Interpreter ABI Platform Actions
lite_taskman-0.9.1-py3-none-any.whl Python 3 none any Details for lite_taskman-0.9.1-py3-none-any.whl

Total release size: 21.3 kB

Release files / lite_taskman-0.9.1.tar.gz

Download URL lite_taskman-0.9.1.tar.gz
Size 11.2 kB
Tags Source
SHA-256 checksum
How to use checksums
33860c94c58002354abf4226c90a1c7f56b76db18744aaa646104b11846fd64b
BLAKE2b-256 checksum
How to use checksums
6a2f747bd66eb809d268a99c8eac2667cc0ded1a49b241520e49b1aaa95a54b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.10

Release files / lite_taskman-0.9.1-py3-none-any.whl

Download URL lite_taskman-0.9.1-py3-none-any.whl
Size 10.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
03f3ccb43ef759d997c43539c102f133ab591044088316b08bf65db02be25587
BLAKE2b-256 checksum
How to use checksums
462ef93f4e4347662c979bf80605962e28a22f9bcf3e489a0bb09987a28b6cc2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.10

Security for lite-taskman 0.9.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.9.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page