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 the introduction of Execution Profiles, NanoWait now offers a semantic layer to manage wait behavior, allowing you to define the operational context clearly and consistently.
In summary: You request a base time (e.g.,
wait(5)), and NanoWait ensures a safe and context-aware wait that never exceeds the requested time and never falls below a minimum execution floor.
Cross-Platform Stability & Headless Environments
NanoWait has undergone significant structural modifications focused on cross-platform stability, especially for macOS, and safe usage in headless environments (CI, RPA, servers). It explicitly differentiates between graphical and headless modes. In headless environments, no graphical UI is instantiated, preventing crashes like NSWindow should only be instantiated on the main thread on macOS with Tkinter issues. This ensures total stability in macOS, CI/CD pipelines, and remote execution.
🚀 Key Features
- Adaptive Waiting: Dynamically scales wait times based on real-time system metrics.
- 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 handling multiple waits concurrently. - Cross-Platform Stability: Optimized for macOS and headless environments (CI/CD, Docker).
- 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.
- Ultra-Adaptive Auto Wait (
wait_auto): Automatically computes the safest and fastest interval for any action without manual configuration.
🛠️ Installation
Install the core package via pip:
pip install nano_wait
Required Dependencies
For adaptive features (CPU/RAM/Wi-Fi awareness) to function, install the following:
pip install psutil pywifi
Optional Module — Vision Mode
Visual waiting (icon/state detection) is available in a dedicated package to keep the core engine lightweight:
pip install nano-wait-vision
Note: If Vision Mode is not installed, NanoWait will raise a clear runtime error when visual functionalities are requested.
💡 Quick Start
Standard vs. Adaptive Wait
from nano_wait import wait
import time
# Adaptive wait (Up to 5 seconds, adjusted by system load)
start = time.time()
wait(5)
print(f"nano_wait.wait(): {time.time() - start:.2f}s")
NanoWait never waits longer than the requested base time and applies a minimum internal delay of 50 ms to prevent excessive CPU usage.
🆕 Ultra-Adaptive Auto Wait (wait_auto)
The new wait_auto function is a zero-configuration adaptive wait designed for PyAutoGUI or any automation workflow.
It automatically:
- Estimates the optimal wait time for the system and network.
- Considers CPU, RAM, and Wi-Fi signal strength.
- Chooses the minimal safe interval between actions.
- Applies the selected Execution Profile automatically.
- Logs and prints the wait decision (optional).
- Works out-of-the-box with loops and sequences in automation scripts.
Basic Usage
from nano_wait.nano_wait_auto import wait_auto
# Simple auto wait (calculates safe interval)
interval = wait_auto(verbose=True)
print(f"Interval calculated: {interval:.3f}s")
Advanced Usage with Smart Options
from nano_wait.nano_wait_auto import wait_auto
# Auto wait with Execution Profile, optional Wi-Fi awareness, and logging
interval = wait_auto(
wifi="MyNetwork_5G",
profile="ci",
verbose=True,
log=True,
telemetry=True
)
print(f"Interval applied: {interval:.3f}s")
Integration with PyAutoGUI Example
import pyautogui
from nano_wait.nano_wait_auto import wait_auto
# Example automation sequence
pyautogui.click(100, 200)
wait_auto() # Automatically computes next safe interval
pyautogui.write("Hello, world!")
wait_auto(verbose=True) # Logs decision
Key benefit: You don’t need to manually set times, speeds, or factors—wait_auto intelligently adapts to the system and environment.
⚡️ Asynchronous Support (wait_async)
NanoWait is fully compatible with asynchronous environments like FastAPI, asyncio-based bots, and web scrapers. The wait_async function is non-blocking, ensuring the event loop remains free.
Usage in Async Code (Concise Example)
import asyncio
from nano_wait import wait_async
async def main():
# Non-blocking wait for up to 2 seconds
result = await wait_async(2, smart=True)
print(f"Wait finished in: {result:.3f}s")
if __name__ == "__main__":
asyncio.run(main())
🌐 Parallel Execution (wait_pool)
Run multiple adaptive waits in parallel—ideal for batch automation or concurrent UI interactions.
Conditional Cancellation (cancel_if)
import psutil
from nano_wait import wait_pool
def heavy_load():
return psutil.cpu_percent() > 80
results = wait_pool([1, 2, 3], cancel_if=heavy_load)
⚙️ Core API Reference
| Function | Sync | Async | Parallel | Cancelable |
|---|---|---|---|---|
wait |
✅ | ❌ | ❌ | ❌ |
wait_async |
❌ | ✅ | ❌ | ❌ |
wait_pool |
✅ | ❌ | ✅ | ✅ |
wait_pool_async |
❌ | ✅ | ✅ | ✅ |
wait_auto |
✅ | ❌ | ❌ | ❌ |
📄 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.1.tar.gz.
File metadata
- Download URL: nano_wait-5.0.1.tar.gz
- Upload date:
- Size: 17.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a5fc55384c414d1b7a073080c982121a630e1ca46f27aa790747f0b5c7633e0
|
|
| MD5 |
6a4b63df868cc1ce739dae24210df1af
|
|
| BLAKE2b-256 |
51d0a914e8b0d8417f90f5247a5dd2e5a9b637780292e1cbcb67933940f932e4
|
File details
Details for the file nano_wait-5.0.1-py3-none-any.whl.
File metadata
- Download URL: nano_wait-5.0.1-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 |
b81d95324f0dcc45268d6e78c32f3ab5f90e854ad00e4854a99c628c3459bbca
|
|
| MD5 |
6fac84ffa18636105779e22d12995574
|
|
| BLAKE2b-256 |
3dc24a565d744c027da5b1faaf390e9c187aa2483427342e20befc6bbba20a5a
|