Adaptive waiting and execution engine — replaces time.sleep() with system-aware, deterministic waiting.
Project description
NanoWait: The Adaptive Wait Engine for Python
NanoWait is a deterministic and adaptive execution wait engine designed to replace Python's standard time.sleep(). Instead of waiting for a fixed duration, NanoWait dynamically adjusts the wait time based on system load (CPU/RAM) and optionally Wi-Fi signal strength, ensuring automation scripts remain reliable even in slow or overloaded environments.
With Execution Profiles, NanoWait offers a semantic layer to manage wait behavior, allowing you to define the operational context clearly and consistently.
Now with Deterministic Condition Waiting, NanoWait can also wait for state changes — not just time.
In summary: You request a base time (e.g.,
wait(5)), or a condition (e.g.,wait(lambda: ready())), and NanoWait ensures a safe, context-aware wait that never exceeds the requested constraints and never falls below a minimum execution floor.
Cross-Platform Stability & Headless Environments
NanoWait has been optimized for cross-platform stability, especially macOS, and safe usage in headless environments (CI, RPA, servers). In headless environments, no graphical UI is instantiated, preventing crashes such as NSWindow should only be instantiated on the main thread on macOS.
This ensures total stability in CI/CD pipelines, Docker containers, and remote execution.
🚀 Key Features
- Adaptive Waiting: Dynamically scales wait times based on real-time system metrics.
- Deterministic Condition Waiting (
wait(until=...)): Wait for Python conditions instead of fixed delays. - Execution Profiles: Semantic presets for CI, RPA, Testing, and more.
- Async Support: Native
wait_asyncfor non-blocking execution inasyncioenvironments. - Parallel Execution:
wait_poolandwait_pool_asyncfor multiple waits concurrently. - Ultra-Adaptive Auto Wait (
wait_auto): Automatically computes the safest and fastest interval without manual configuration. - Cross-Platform Stability: Optimized for macOS and headless environments.
- Explain Mode: Auditable decision reports for full transparency.
- CLI Support: Powerful command-line interface for quick tasks.
- Local Telemetry: Opt-in system for analyzing wait behavior without remote data collection.
🆕 Deterministic Condition Waiting (wait(until=...))
NanoWait 5.1 introduces condition-based waiting, eliminating the need for manual polling loops like:
while not something_ready():
time.sleep(0.3)
Instead, you can now write:
from nano_wait import wait
wait(lambda: something_ready(), timeout=10)
What This Solves
- Removes fragile polling loops
- Prevents excessive CPU usage
- Applies adaptive backoff automatically
- Respects a minimum 50ms interval
- Stops safely at timeout
- Integrates with telemetry and profiles
Condition Waiting Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
until |
Callable |
None |
Condition function returning True when ready |
timeout |
float |
15.0 |
Maximum time allowed |
profile |
str |
"auto" |
Execution profile |
smart |
bool |
False |
Enables smart speed detection |
verbose |
bool |
False |
Prints polling intervals |
telemetry |
bool |
False |
Records adaptive adjustments |
explain |
bool |
False |
Returns decision report |
Basic Condition Usage
from nano_wait import wait
def api_ready():
return check_server_status() == 200
result = wait(api_ready, timeout=5)
if result:
print("API is ready.")
else:
print("Timeout reached.")
Waiting for File Availability
import os
from nano_wait import wait
wait(lambda: os.path.exists("output.txt"), timeout=10)
Adaptive Polling in Action
NanoWait dynamically adjusts polling intervals:
- Heavy CPU load → slightly longer interval
- Light system load → faster responsiveness
- Never below 50ms floor
- Never exceeds timeout
This makes it safe for:
- Backend services
- CI pipelines
- API retry loops
- Scraping workflows
- Database readiness checks
🆕 Ultra-Adaptive Auto Wait (wait_auto)
wait_auto remains the default engine behind wait() when no condition is provided.
It automatically:
- Estimates optimal wait time
- Considers CPU and Wi-Fi
- Applies Execution Profile
- Learns from previous runs
- Applies adaptive bias
Example: Automation Flow
import pyautogui
from nano_wait import wait
pyautogui.click(100, 200)
wait()
pyautogui.write("Hello")
wait()
pyautogui.press("enter")
⚡ Async Condition Waiting
import asyncio
from nano_wait import wait_async
async def main():
result = await wait_async(lambda: check_ready(), timeout=5)
print(result)
asyncio.run(main())
Works seamlessly in:
- FastAPI
- Async bots
- Scrapers
- Async task queues
💡 Quick Start
Standard Adaptive Time Wait
from nano_wait import wait
wait(5)
Deterministic Condition Wait
wait(lambda: database_ready(), timeout=10)
🌐 Parallel Execution (wait_pool)
from nano_wait import wait_pool
results = wait_pool([1, 2, 3])
⚙️ Core API Reference
| Function | Sync | Async | Condition | Parallel | Cancelable |
|---|---|---|---|---|---|
wait |
✅ | ❌ | ✅ | ❌ | ❌ |
wait_async |
❌ | ✅ | ✅ | ❌ | ❌ |
wait_pool |
✅ | ❌ | ❌ | ✅ | ✅ |
wait_pool_async |
❌ | ✅ | ❌ | ✅ | ✅ |
wait_auto |
✅ | ❌ | ❌ | ❌ | ❌ |
🛠 Installation
pip install nano_wait
Required Dependencies
pip install psutil pywifi
📄 License
Distributed under the MIT License. See LICENSE for more information.
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nano_wait-5.0.3.tar.gz.
File metadata
- Download URL: nano_wait-5.0.3.tar.gz
- Upload date:
- Size: 17.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7734de0b9f90edd61352cad2dd665a01fde1041047694257d6f8b44bd199be4
|
|
| MD5 |
da588eaa80e2f2118e8316efdefa231f
|
|
| BLAKE2b-256 |
7e6ce155d364227ead7268dac2dd9ff62d28889d6ef995dc84c9096b91509805
|
File details
Details for the file nano_wait-5.0.3-py3-none-any.whl.
File metadata
- Download URL: nano_wait-5.0.3-py3-none-any.whl
- Upload date:
- Size: 17.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c02be4b0bf643f1577430f906bb868f7b1fbb3da69b66c87fa83ef6b1649d79e
|
|
| MD5 |
5ba9ad63efed5f4c0008a08134046503
|
|
| BLAKE2b-256 |
5ce7779fde570d4529b4910378c58a8cb5323d039bdabcacfb9fd1bb7ad20073
|