Skip to main content

Intelligent Futures

A practical, extensible laboratory for better Python concurrency: a bounded concurrent.futures.Executor, transparent workload measurements, an experimental online scheduler, and a growing library of optimization concepts.

Status: alpha research prototype. No universal speedup is promised. The “intelligence” is an auditable EWMA latency learner with controlled exploration, not an LLM, code generator, or automatic proof of process safety.

Public repository: yflop/concurrent-futures-ai.

Start in a minute

Python 3.10 or newer; no runtime dependencies.

python -m pip install -e .
python -m unittest discover -s tests -v
python examples/profiling.py
from intelligent_futures import IntelligentExecutor, TaskHints

def square(n):
    return n * n

if __name__ == "__main__":  # required when using spawn-based processes
    with IntelligentExecutor(max_workers=4, process_workers=2,
                             max_pending=32, policy="hints") as executor:
        ordinary = executor.submit(square, 7)  # conservative thread routing
        cpu = executor.submit_task(
            square, 9,
            hints=TaskHints(kind="cpu", key="square", process_safe=True),
        )
        print(ordinary.result(), cpu.result())
    print(executor.snapshot())

Tiny tasks like square generally do not benefit from process overhead. This example demonstrates semantics, not a performance recommendation.

What works today

  • Standard-library Future objects, wait, as_completed, map, exceptions, callbacks, and best-effort queued cancellation
  • Independent thread/process worker budgets; processes disabled by default
  • max_pending bounds all unfinished accepted tasks, queued plus running
  • Blocking backpressure, optional admission timeout, and shutdown wakeup
  • Bounded per-key/backend latency profiles, failures, and aggregate counters
  • Safe hint routing, thread-only mode, custom policies, and a policy factory registry
  • Experimental EWMA latency selection with deterministic exploration
  • Ordered map_bounded for streaming inputs and bounded retained results
  • Runnable examples, reproducible baseline benchmarks, tests, packaging, and CI

Safety first

submit(fn, *args, **kwargs) keeps the standard keyword contract, including a function argument named hints. Use submit_task to reserve the scheduling hints keyword. Process routing requires both a configured process pool and process_safe=True, even from a custom policy. The flag is your assertion: functions and arguments must be pickleable, importable, and semantically safe in a separate process. Do not rely on mutated thread-shared globals across processes.

No retries, speculative duplicates, hard timeouts, task killing, distributed execution, automatic worker resizing, or remote AI calls are implemented. Cancellation never stops a running callable. Context-manager exit waits for work. Blocking nested submissions into a saturated executor can deadlock: orchestrate from outside worker tasks, or use a finite submit_timeout and handle failure.

Choose the right policy

Policy Behavior Recommended use
threads Always threads Closures, shared state, general I/O
hints CPU + explicit process consent routes to processes Known workloads, predictable routing
adaptive (default) Eligible workloads can explore both backends and learn EWMA completion latency Controlled experiments with comparable task keys

The learner optimizes observed submission-to-completion latency, including pool queueing and serialization, excluding admission wait. It cannot identify causal backend advantages under arbitrary changing load. Errors are counted but do not train latency. Share keys only across comparable work. Profiles are executor-local, not persisted, and evicted with an LRU bound. The policy's exploration counter is global to that policy instance. Keep stateful policy instances private to one executor.

Browse the concept library

python -m intelligent_futures queue --status planned
python -m intelligent_futures --status experimental --json

The bundled ConceptRegistry validates unique IDs, status labels, and acyclic dependencies. Catalog content never imports or executes plugin code.

API and documents

Appendices separate implemented mechanisms from experimental and planned work. Ideas are extension proposals, not hidden features. Benchmark raw data is the source of performance claims; a measured loss is a useful result too.

Development

PYTHONPATH=src python -m unittest discover -s tests -v
python tools/verify.py --examples
python -m compileall -q src examples benchmarks tests
python -m pip wheel . --no-deps -w dist

See benchmark help for workload sizes, repeated cold/warm comparisons, and JSON output. A hybrid executor may use more total workers than a single baseline pool; compare resource budgets before interpreting a timing ratio.

Measured result

The included five-repeat reference run did not beat the best stdlib pool: for warm CPU, synthetic I/O, and mixed batches, adaptive took approximately 548, 164, and 344 ms versus 256, 122, and 196 ms for the best measured stdlib configuration. Worker allocation and hint information differ; see the full validation record. Treat this as an extensible research baseline with tested contracts, not a performance upgrade by default.

License

Original code and documentation are MIT licensed. Activepieces is a conceptual inspiration, not a dependency or copied implementation. Third-party linked material retains its own license.

Cancellation churn and memory

The admission limit is not a strict physical queue or memory bound. Cancelling a queued Future frees logical admission immediately, but stdlib pools can retain its cancelled work item and arguments until a worker drains the queue. Repeated submit/cancel loops behind blocked workers can therefore accumulate tombstones. Rate-limit producers and cancellation churn; do not treat this executor as a hard memory limiter. A removable bounded physical queue is planned work.

Metadata

Release files for intelligent-futures 0.1.0

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

Source distribution (sdist)

Source distribution for intelligent-futures 0.1.0
File Size Uploaded
intelligent_futures-0.1.0.tar.gz 404.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for intelligent-futures 0.1.0
File Interpreter ABI Platform
intelligent_futures-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 431.0 kB

Release files / intelligent_futures-0.1.0.tar.gz

Download URL intelligent_futures-0.1.0.tar.gz
Size 404.5 kB
Tags Source
SHA-256 checksum
How to use checksums
73a188d9eef63380edcc6ea0da8d0dab82e931b13bde7f7f5174565d9c6dee40
BLAKE2b-256 checksum
How to use checksums
3ca5086a7c3f9b06be9b16d003c57ed44654a8312f568282c08eeaea44785c4d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / intelligent_futures-0.1.0-py3-none-any.whl

Download URL intelligent_futures-0.1.0-py3-none-any.whl
Size 26.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a6e72369e4bc83bdd0404304f809879f365fa4c3ae39d73ca61a613ae5977875
BLAKE2b-256 checksum
How to use checksums
85a5640fb0751804a82161cf39d81c4dd251f1b27838111fa9bdb7cde2e48d17
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release history Release notifications | RSS feed

0.3.0

2 release files

0.2.0

2 release files

This release

0.1.0 This release

2 release files

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