pyarallel 0.1.1__tar.gz → 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyarallel-0.1.1 → pyarallel-0.1.2}/.gitignore +4 -0
- pyarallel-0.1.2/Makefile +36 -0
- {pyarallel-0.1.1 → pyarallel-0.1.2}/PKG-INFO +160 -60
- {pyarallel-0.1.1 → pyarallel-0.1.2}/README.md +159 -59
- {pyarallel-0.1.1 → pyarallel-0.1.2}/TASKS.md +12 -12
- pyarallel-0.1.2/docs/api-reference/configuration-api.md +49 -0
- pyarallel-0.1.2/docs/api-reference/decorators.md +64 -0
- pyarallel-0.1.2/docs/api-reference/rate-limiting.md +60 -0
- pyarallel-0.1.2/docs/development/CONTRIBUTING.md +56 -0
- pyarallel-0.1.2/docs/development/roadmap.md +74 -0
- pyarallel-0.1.2/docs/getting-started/installation.md +61 -0
- pyarallel-0.1.2/docs/getting-started/quickstart.md +94 -0
- pyarallel-0.1.2/docs/index.md +61 -0
- pyarallel-0.1.2/docs/user-guide/advanced-features.md +174 -0
- pyarallel-0.1.2/docs/user-guide/best-practices.md +207 -0
- pyarallel-0.1.2/docs/user-guide/configuration.md +150 -0
- pyarallel-0.1.2/mkdocs.yml +46 -0
- {pyarallel-0.1.1 → pyarallel-0.1.2}/pyarallel/config.py +64 -2
- pyarallel-0.1.2/pyarallel/config_manager.py +342 -0
- {pyarallel-0.1.1 → pyarallel-0.1.2}/pyarallel/core.py +69 -120
- pyarallel-0.1.2/pyarallel/env_config.py +57 -0
- {pyarallel-0.1.1 → pyarallel-0.1.2}/pyproject.toml +13 -1
- pyarallel-0.1.2/sandbox/sandbox_test.py +100 -0
- {pyarallel-0.1.1 → pyarallel-0.1.2}/setup.py +1 -1
- pyarallel-0.1.2/tests/conftest.py +108 -0
- {pyarallel-0.1.1 → pyarallel-0.1.2}/tests/test_config_manager.py +18 -16
- pyarallel-0.1.2/tests/test_decorator_config.py +121 -0
- pyarallel-0.1.2/tests/test_env_config.py +64 -0
- {pyarallel-0.1.1 → pyarallel-0.1.2}/tests/test_pyarallel.py +52 -45
- pyarallel-0.1.2/tests/test_runtime_config.py +114 -0
- pyarallel-0.1.2/uv.lock +871 -0
- pyarallel-0.1.1/pyarallel/config_manager.py +0 -90
- pyarallel-0.1.1/uv.lock +0 -7
- {pyarallel-0.1.1 → pyarallel-0.1.2}/.python-version +0 -0
- {pyarallel-0.1.1 → pyarallel-0.1.2}/CONTRIBUTING.md +0 -0
- {pyarallel-0.1.1 → pyarallel-0.1.2}/LICENSE.md +0 -0
- {pyarallel-0.1.1 → pyarallel-0.1.2}/pyarallel/__init__.py +0 -0
pyarallel-0.1.2/Makefile
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
.PHONY: help test docs-serve docs-deploy format lint clean
|
|
2
|
+
|
|
3
|
+
help:
|
|
4
|
+
@echo "Available commands:"
|
|
5
|
+
@echo " make test Run pytest suite"
|
|
6
|
+
@echo " make docs-serve Start mkdocs development server"
|
|
7
|
+
@echo " make docs-deploy Deploy documentation to GitHub Pages"
|
|
8
|
+
@echo " make format Format code with black and isort"
|
|
9
|
+
@echo " make lint Run mypy for type checking"
|
|
10
|
+
@echo " make clean Remove build artifacts"
|
|
11
|
+
|
|
12
|
+
test:
|
|
13
|
+
pytest tests/ -v
|
|
14
|
+
|
|
15
|
+
docs-serve:
|
|
16
|
+
mkdocs serve
|
|
17
|
+
|
|
18
|
+
docs-deploy:
|
|
19
|
+
python -c "import pyarallel; from pathlib import Path; yml = Path('mkdocs.yml').read_text(); Path('mkdocs.yml').write_text(yml.replace('version: .*', f'version: {pyarallel.__version__}'))"
|
|
20
|
+
mkdocs gh-deploy
|
|
21
|
+
|
|
22
|
+
format:
|
|
23
|
+
black .
|
|
24
|
+
isort .
|
|
25
|
+
|
|
26
|
+
lint:
|
|
27
|
+
mypy pyarallel/
|
|
28
|
+
|
|
29
|
+
clean:
|
|
30
|
+
rm -rf build/
|
|
31
|
+
rm -rf dist/
|
|
32
|
+
rm -rf *.egg-info/
|
|
33
|
+
find . -type d -name __pycache__ -exec rm -rf {} +
|
|
34
|
+
find . -type f -name '*.pyc' -delete
|
|
35
|
+
find . -type f -name '*.pyo' -delete
|
|
36
|
+
find . -type f -name '*.pyd' -delete
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pyarallel
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: A powerful parallel execution library for Python
|
|
5
5
|
Project-URL: Homepage, https://github.com/oneryalcin/pyarallel
|
|
6
6
|
Project-URL: Repository, https://github.com/oneryalcin/pyarallel.git
|
|
@@ -39,6 +39,9 @@ Description-Content-Type: text/markdown
|
|
|
39
39
|
|
|
40
40
|
# Pyarallel
|
|
41
41
|
|
|
42
|
+
[](https://oneryalcin.github.io/pyarallel/) [](https://pypi.org/project/pyarallel/) [](https://pepy.tech/project/pyarallel)
|
|
43
|
+
|
|
44
|
+
|
|
42
45
|
A powerful,feature-rich parallel execution library for Python that makes concurrent programming easy and efficient.
|
|
43
46
|
|
|
44
47
|
## Features
|
|
@@ -56,6 +59,10 @@ A powerful,feature-rich parallel execution library for Python that makes concurr
|
|
|
56
59
|
- Memory-efficient with automatic cleanup
|
|
57
60
|
- Comprehensive error handling
|
|
58
61
|
|
|
62
|
+
## Documentation
|
|
63
|
+
|
|
64
|
+
Check out the [documentation](https://oneryalcin.github.io/pyarallel/) for detailed usage instructions and examples.
|
|
65
|
+
|
|
59
66
|
## Installation
|
|
60
67
|
|
|
61
68
|
```bash
|
|
@@ -180,6 +187,157 @@ results = process_large_dataset(items)
|
|
|
180
187
|
return {"error": str(e), "item": item}
|
|
181
188
|
```
|
|
182
189
|
|
|
190
|
+
## Configuration
|
|
191
|
+
|
|
192
|
+
Pyarallel features a robust configuration system built on Pydantic, offering type validation, environment variable support, and thread-safe configuration management.
|
|
193
|
+
|
|
194
|
+
### Basic Configuration
|
|
195
|
+
|
|
196
|
+
```python
|
|
197
|
+
from pyarallel import ConfigManager
|
|
198
|
+
|
|
199
|
+
# Get the thread-safe singleton configuration manager
|
|
200
|
+
config = ConfigManager.get_instance()
|
|
201
|
+
|
|
202
|
+
# Update configuration with type validation
|
|
203
|
+
config.update_config({
|
|
204
|
+
"execution": {
|
|
205
|
+
"default_max_workers": 8,
|
|
206
|
+
"default_executor_type": "thread",
|
|
207
|
+
"default_batch_size": 100,
|
|
208
|
+
"prewarm_pools": True
|
|
209
|
+
},
|
|
210
|
+
"rate_limiting": {
|
|
211
|
+
"default_rate": 1000,
|
|
212
|
+
"default_interval": "minute",
|
|
213
|
+
"burst_tolerance": 1.5
|
|
214
|
+
}
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
# Access configuration using dot notation
|
|
218
|
+
workers = config.execution.default_max_workers
|
|
219
|
+
rate = config.rate_limiting.default_rate
|
|
220
|
+
|
|
221
|
+
# Category-specific updates
|
|
222
|
+
config.update_execution(max_workers=16)
|
|
223
|
+
config.update_rate_limiting(rate=2000)
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### Environment Variables
|
|
227
|
+
|
|
228
|
+
Configure Pyarallel using environment variables with the `PYARALLEL_` prefix. The system automatically handles type coercion and validation:
|
|
229
|
+
|
|
230
|
+
```bash
|
|
231
|
+
# Execution settings
|
|
232
|
+
export PYARALLEL_MAX_WORKERS=4
|
|
233
|
+
export PYARALLEL_EXECUTOR_TYPE=thread
|
|
234
|
+
export PYARALLEL_BATCH_SIZE=100
|
|
235
|
+
|
|
236
|
+
# Rate limiting
|
|
237
|
+
export PYARALLEL_RATE_LIMIT=100/minute
|
|
238
|
+
export PYARALLEL_FAIL_FAST=true
|
|
239
|
+
|
|
240
|
+
# Complex values (using JSON)
|
|
241
|
+
export PYARALLEL_RETRY_CONFIG='{"max_attempts": 3, "backoff": 1.5}'
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### Configuration Schema
|
|
245
|
+
|
|
246
|
+
The configuration system uses a structured schema with the following categories:
|
|
247
|
+
|
|
248
|
+
```python
|
|
249
|
+
{
|
|
250
|
+
"execution": {
|
|
251
|
+
"default_max_workers": int, # Default worker count
|
|
252
|
+
"default_executor_type": str, # "thread" or "process"
|
|
253
|
+
"default_batch_size": Optional[int], # Default batch size
|
|
254
|
+
"prewarm_pools": bool # Enable worker prewarming
|
|
255
|
+
},
|
|
256
|
+
"rate_limiting": {
|
|
257
|
+
"default_rate": Optional[float], # Default operations per interval
|
|
258
|
+
"default_interval": str, # "second", "minute", "hour"
|
|
259
|
+
"burst_tolerance": float # Burst allowance factor
|
|
260
|
+
},
|
|
261
|
+
"error_handling": {
|
|
262
|
+
"max_retries": int, # Maximum retry attempts
|
|
263
|
+
"retry_backoff": float, # Backoff multiplier
|
|
264
|
+
"fail_fast": bool # Stop on first error
|
|
265
|
+
},
|
|
266
|
+
"monitoring": {
|
|
267
|
+
"enable_logging": bool, # Enable detailed logging
|
|
268
|
+
"log_level": str, # Logging level
|
|
269
|
+
"sentry_dsn": Optional[str], # Sentry integration
|
|
270
|
+
"metrics_enabled": bool # Enable metrics collection
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Best Practices
|
|
276
|
+
|
|
277
|
+
1. **Use Environment Variables for Deployment**:
|
|
278
|
+
- Keep configuration in environment variables for different environments
|
|
279
|
+
- Use the `PYARALLEL_` prefix to avoid conflicts
|
|
280
|
+
- Complex values can be passed as JSON strings
|
|
281
|
+
|
|
282
|
+
2. **Validate Configuration Early**:
|
|
283
|
+
- Set up configuration at application startup
|
|
284
|
+
- Use type validation to catch issues early
|
|
285
|
+
- Test configuration with sample data
|
|
286
|
+
|
|
287
|
+
3. **Thread-Safe Updates**:
|
|
288
|
+
- Always use `ConfigManager.get_instance()` for thread-safe access
|
|
289
|
+
- Make configuration changes before starting parallel operations
|
|
290
|
+
- Use category-specific update methods for better type safety
|
|
291
|
+
|
|
292
|
+
4. **Configuration Inheritance**:
|
|
293
|
+
- Global settings serve as defaults
|
|
294
|
+
- Decorator arguments override global configuration
|
|
295
|
+
- Environment variables take precedence over code-based configuration
|
|
296
|
+
|
|
297
|
+
### Runtime Configuration Warnings
|
|
298
|
+
|
|
299
|
+
Pyarallel includes built-in warnings to help identify potential performance issues:
|
|
300
|
+
|
|
301
|
+
```python
|
|
302
|
+
# Warning for high worker count
|
|
303
|
+
@parallel(max_workers=150) # Triggers warning about system impact
|
|
304
|
+
def high_worker_task(): ...
|
|
305
|
+
|
|
306
|
+
# Warning for inefficient process pool configuration
|
|
307
|
+
@parallel(
|
|
308
|
+
executor_type="process",
|
|
309
|
+
batch_size=1 # Triggers warning about inefficient batch size
|
|
310
|
+
)
|
|
311
|
+
def inefficient_task(): ...
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### Configuration Inheritance
|
|
315
|
+
|
|
316
|
+
Pyarallel uses a hierarchical configuration system:
|
|
317
|
+
|
|
318
|
+
1. **Default Values**: Built-in defaults (4 workers, thread executor, batch size 10)
|
|
319
|
+
2. **Global Configuration**: Set via ConfigManager
|
|
320
|
+
3. **Environment Variables**: Override global config
|
|
321
|
+
4. **Decorator Arguments**: Highest precedence, override all other settings
|
|
322
|
+
|
|
323
|
+
```python
|
|
324
|
+
# Global configuration (lowest precedence)
|
|
325
|
+
config = ConfigManager.get_instance()
|
|
326
|
+
config.update_config({
|
|
327
|
+
"execution": {
|
|
328
|
+
"default_max_workers": 8,
|
|
329
|
+
"default_executor_type": "thread"
|
|
330
|
+
}
|
|
331
|
+
})
|
|
332
|
+
|
|
333
|
+
# Environment variables (middle precedence)
|
|
334
|
+
# export PYARALLEL_MAX_WORKERS=16
|
|
335
|
+
|
|
336
|
+
# Decorator arguments (highest precedence)
|
|
337
|
+
@parallel(max_workers=4) # This value wins
|
|
338
|
+
def my_func(): ...
|
|
339
|
+
```
|
|
340
|
+
|
|
183
341
|
## Roadmap
|
|
184
342
|
|
|
185
343
|
### Observability & Debugging
|
|
@@ -235,7 +393,6 @@ results = process_large_dataset(items)
|
|
|
235
393
|
- Log analysis utilities
|
|
236
394
|
- Telemetry visualization
|
|
237
395
|
|
|
238
|
-
|
|
239
396
|
### Enterprise Features
|
|
240
397
|
- **Integration**
|
|
241
398
|
- Distributed tracing (OpenTelemetry)
|
|
@@ -280,61 +437,4 @@ Contributions are welcome! Please check out our [Contributing Guide](CONTRIBUTIN
|
|
|
280
437
|
|
|
281
438
|
## License
|
|
282
439
|
|
|
283
|
-
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
284
|
-
|
|
285
|
-
## Configuration
|
|
286
|
-
|
|
287
|
-
Pyarallel provides a flexible configuration system that allows you to customize its behavior globally or per-function:
|
|
288
|
-
|
|
289
|
-
### Basic Configuration
|
|
290
|
-
|
|
291
|
-
```python
|
|
292
|
-
from pyarallel import ConfigManager
|
|
293
|
-
|
|
294
|
-
# Get the global configuration manager
|
|
295
|
-
config = ConfigManager.get_instance()
|
|
296
|
-
|
|
297
|
-
# Update configuration
|
|
298
|
-
config.update_config({
|
|
299
|
-
"max_workers": 8,
|
|
300
|
-
"timeout": 60.0,
|
|
301
|
-
"debug": True
|
|
302
|
-
})
|
|
303
|
-
```
|
|
304
|
-
|
|
305
|
-
### Configuration Options
|
|
306
|
-
|
|
307
|
-
- **Execution Settings**
|
|
308
|
-
- `max_workers`: Maximum number of worker processes/threads (default: 4)
|
|
309
|
-
- `timeout`: Default timeout for parallel operations in seconds (default: 30.0)
|
|
310
|
-
|
|
311
|
-
- **Resource Management**
|
|
312
|
-
- `memory_limit`: Memory limit per worker in bytes (default: None)
|
|
313
|
-
- `cpu_affinity`: Enable CPU affinity for workers (default: False)
|
|
314
|
-
|
|
315
|
-
- **Logging and Debugging**
|
|
316
|
-
- `debug`: Enable debug mode (default: False)
|
|
317
|
-
- `log_level`: Logging level (default: "INFO")
|
|
318
|
-
|
|
319
|
-
### Environment Variables
|
|
320
|
-
|
|
321
|
-
You can configure Pyarallel using environment variables with the `PYARALLEL_` prefix:
|
|
322
|
-
|
|
323
|
-
```bash
|
|
324
|
-
PYARALLEL_MAX_WORKERS=4
|
|
325
|
-
PYARALLEL_TIMEOUT=60.0
|
|
326
|
-
PYARALLEL_DEBUG=true
|
|
327
|
-
```
|
|
328
|
-
|
|
329
|
-
### Configuration Files
|
|
330
|
-
|
|
331
|
-
Load configuration from JSON, YAML, or TOML files:
|
|
332
|
-
|
|
333
|
-
```python
|
|
334
|
-
from pyarallel import PyarallelConfig
|
|
335
|
-
|
|
336
|
-
# Load from file
|
|
337
|
-
config = PyarallelConfig.from_file("pyarallel.yaml")
|
|
338
|
-
|
|
339
|
-
# Convert to dictionary
|
|
340
|
-
config_dict = config.to_dict()
|
|
440
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# Pyarallel
|
|
2
2
|
|
|
3
|
+
[](https://oneryalcin.github.io/pyarallel/) [](https://pypi.org/project/pyarallel/) [](https://pepy.tech/project/pyarallel)
|
|
4
|
+
|
|
5
|
+
|
|
3
6
|
A powerful,feature-rich parallel execution library for Python that makes concurrent programming easy and efficient.
|
|
4
7
|
|
|
5
8
|
## Features
|
|
@@ -17,6 +20,10 @@ A powerful,feature-rich parallel execution library for Python that makes concurr
|
|
|
17
20
|
- Memory-efficient with automatic cleanup
|
|
18
21
|
- Comprehensive error handling
|
|
19
22
|
|
|
23
|
+
## Documentation
|
|
24
|
+
|
|
25
|
+
Check out the [documentation](https://oneryalcin.github.io/pyarallel/) for detailed usage instructions and examples.
|
|
26
|
+
|
|
20
27
|
## Installation
|
|
21
28
|
|
|
22
29
|
```bash
|
|
@@ -141,6 +148,157 @@ results = process_large_dataset(items)
|
|
|
141
148
|
return {"error": str(e), "item": item}
|
|
142
149
|
```
|
|
143
150
|
|
|
151
|
+
## Configuration
|
|
152
|
+
|
|
153
|
+
Pyarallel features a robust configuration system built on Pydantic, offering type validation, environment variable support, and thread-safe configuration management.
|
|
154
|
+
|
|
155
|
+
### Basic Configuration
|
|
156
|
+
|
|
157
|
+
```python
|
|
158
|
+
from pyarallel import ConfigManager
|
|
159
|
+
|
|
160
|
+
# Get the thread-safe singleton configuration manager
|
|
161
|
+
config = ConfigManager.get_instance()
|
|
162
|
+
|
|
163
|
+
# Update configuration with type validation
|
|
164
|
+
config.update_config({
|
|
165
|
+
"execution": {
|
|
166
|
+
"default_max_workers": 8,
|
|
167
|
+
"default_executor_type": "thread",
|
|
168
|
+
"default_batch_size": 100,
|
|
169
|
+
"prewarm_pools": True
|
|
170
|
+
},
|
|
171
|
+
"rate_limiting": {
|
|
172
|
+
"default_rate": 1000,
|
|
173
|
+
"default_interval": "minute",
|
|
174
|
+
"burst_tolerance": 1.5
|
|
175
|
+
}
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
# Access configuration using dot notation
|
|
179
|
+
workers = config.execution.default_max_workers
|
|
180
|
+
rate = config.rate_limiting.default_rate
|
|
181
|
+
|
|
182
|
+
# Category-specific updates
|
|
183
|
+
config.update_execution(max_workers=16)
|
|
184
|
+
config.update_rate_limiting(rate=2000)
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Environment Variables
|
|
188
|
+
|
|
189
|
+
Configure Pyarallel using environment variables with the `PYARALLEL_` prefix. The system automatically handles type coercion and validation:
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
# Execution settings
|
|
193
|
+
export PYARALLEL_MAX_WORKERS=4
|
|
194
|
+
export PYARALLEL_EXECUTOR_TYPE=thread
|
|
195
|
+
export PYARALLEL_BATCH_SIZE=100
|
|
196
|
+
|
|
197
|
+
# Rate limiting
|
|
198
|
+
export PYARALLEL_RATE_LIMIT=100/minute
|
|
199
|
+
export PYARALLEL_FAIL_FAST=true
|
|
200
|
+
|
|
201
|
+
# Complex values (using JSON)
|
|
202
|
+
export PYARALLEL_RETRY_CONFIG='{"max_attempts": 3, "backoff": 1.5}'
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Configuration Schema
|
|
206
|
+
|
|
207
|
+
The configuration system uses a structured schema with the following categories:
|
|
208
|
+
|
|
209
|
+
```python
|
|
210
|
+
{
|
|
211
|
+
"execution": {
|
|
212
|
+
"default_max_workers": int, # Default worker count
|
|
213
|
+
"default_executor_type": str, # "thread" or "process"
|
|
214
|
+
"default_batch_size": Optional[int], # Default batch size
|
|
215
|
+
"prewarm_pools": bool # Enable worker prewarming
|
|
216
|
+
},
|
|
217
|
+
"rate_limiting": {
|
|
218
|
+
"default_rate": Optional[float], # Default operations per interval
|
|
219
|
+
"default_interval": str, # "second", "minute", "hour"
|
|
220
|
+
"burst_tolerance": float # Burst allowance factor
|
|
221
|
+
},
|
|
222
|
+
"error_handling": {
|
|
223
|
+
"max_retries": int, # Maximum retry attempts
|
|
224
|
+
"retry_backoff": float, # Backoff multiplier
|
|
225
|
+
"fail_fast": bool # Stop on first error
|
|
226
|
+
},
|
|
227
|
+
"monitoring": {
|
|
228
|
+
"enable_logging": bool, # Enable detailed logging
|
|
229
|
+
"log_level": str, # Logging level
|
|
230
|
+
"sentry_dsn": Optional[str], # Sentry integration
|
|
231
|
+
"metrics_enabled": bool # Enable metrics collection
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Best Practices
|
|
237
|
+
|
|
238
|
+
1. **Use Environment Variables for Deployment**:
|
|
239
|
+
- Keep configuration in environment variables for different environments
|
|
240
|
+
- Use the `PYARALLEL_` prefix to avoid conflicts
|
|
241
|
+
- Complex values can be passed as JSON strings
|
|
242
|
+
|
|
243
|
+
2. **Validate Configuration Early**:
|
|
244
|
+
- Set up configuration at application startup
|
|
245
|
+
- Use type validation to catch issues early
|
|
246
|
+
- Test configuration with sample data
|
|
247
|
+
|
|
248
|
+
3. **Thread-Safe Updates**:
|
|
249
|
+
- Always use `ConfigManager.get_instance()` for thread-safe access
|
|
250
|
+
- Make configuration changes before starting parallel operations
|
|
251
|
+
- Use category-specific update methods for better type safety
|
|
252
|
+
|
|
253
|
+
4. **Configuration Inheritance**:
|
|
254
|
+
- Global settings serve as defaults
|
|
255
|
+
- Decorator arguments override global configuration
|
|
256
|
+
- Environment variables take precedence over code-based configuration
|
|
257
|
+
|
|
258
|
+
### Runtime Configuration Warnings
|
|
259
|
+
|
|
260
|
+
Pyarallel includes built-in warnings to help identify potential performance issues:
|
|
261
|
+
|
|
262
|
+
```python
|
|
263
|
+
# Warning for high worker count
|
|
264
|
+
@parallel(max_workers=150) # Triggers warning about system impact
|
|
265
|
+
def high_worker_task(): ...
|
|
266
|
+
|
|
267
|
+
# Warning for inefficient process pool configuration
|
|
268
|
+
@parallel(
|
|
269
|
+
executor_type="process",
|
|
270
|
+
batch_size=1 # Triggers warning about inefficient batch size
|
|
271
|
+
)
|
|
272
|
+
def inefficient_task(): ...
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Configuration Inheritance
|
|
276
|
+
|
|
277
|
+
Pyarallel uses a hierarchical configuration system:
|
|
278
|
+
|
|
279
|
+
1. **Default Values**: Built-in defaults (4 workers, thread executor, batch size 10)
|
|
280
|
+
2. **Global Configuration**: Set via ConfigManager
|
|
281
|
+
3. **Environment Variables**: Override global config
|
|
282
|
+
4. **Decorator Arguments**: Highest precedence, override all other settings
|
|
283
|
+
|
|
284
|
+
```python
|
|
285
|
+
# Global configuration (lowest precedence)
|
|
286
|
+
config = ConfigManager.get_instance()
|
|
287
|
+
config.update_config({
|
|
288
|
+
"execution": {
|
|
289
|
+
"default_max_workers": 8,
|
|
290
|
+
"default_executor_type": "thread"
|
|
291
|
+
}
|
|
292
|
+
})
|
|
293
|
+
|
|
294
|
+
# Environment variables (middle precedence)
|
|
295
|
+
# export PYARALLEL_MAX_WORKERS=16
|
|
296
|
+
|
|
297
|
+
# Decorator arguments (highest precedence)
|
|
298
|
+
@parallel(max_workers=4) # This value wins
|
|
299
|
+
def my_func(): ...
|
|
300
|
+
```
|
|
301
|
+
|
|
144
302
|
## Roadmap
|
|
145
303
|
|
|
146
304
|
### Observability & Debugging
|
|
@@ -196,7 +354,6 @@ results = process_large_dataset(items)
|
|
|
196
354
|
- Log analysis utilities
|
|
197
355
|
- Telemetry visualization
|
|
198
356
|
|
|
199
|
-
|
|
200
357
|
### Enterprise Features
|
|
201
358
|
- **Integration**
|
|
202
359
|
- Distributed tracing (OpenTelemetry)
|
|
@@ -241,61 +398,4 @@ Contributions are welcome! Please check out our [Contributing Guide](CONTRIBUTIN
|
|
|
241
398
|
|
|
242
399
|
## License
|
|
243
400
|
|
|
244
|
-
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
245
|
-
|
|
246
|
-
## Configuration
|
|
247
|
-
|
|
248
|
-
Pyarallel provides a flexible configuration system that allows you to customize its behavior globally or per-function:
|
|
249
|
-
|
|
250
|
-
### Basic Configuration
|
|
251
|
-
|
|
252
|
-
```python
|
|
253
|
-
from pyarallel import ConfigManager
|
|
254
|
-
|
|
255
|
-
# Get the global configuration manager
|
|
256
|
-
config = ConfigManager.get_instance()
|
|
257
|
-
|
|
258
|
-
# Update configuration
|
|
259
|
-
config.update_config({
|
|
260
|
-
"max_workers": 8,
|
|
261
|
-
"timeout": 60.0,
|
|
262
|
-
"debug": True
|
|
263
|
-
})
|
|
264
|
-
```
|
|
265
|
-
|
|
266
|
-
### Configuration Options
|
|
267
|
-
|
|
268
|
-
- **Execution Settings**
|
|
269
|
-
- `max_workers`: Maximum number of worker processes/threads (default: 4)
|
|
270
|
-
- `timeout`: Default timeout for parallel operations in seconds (default: 30.0)
|
|
271
|
-
|
|
272
|
-
- **Resource Management**
|
|
273
|
-
- `memory_limit`: Memory limit per worker in bytes (default: None)
|
|
274
|
-
- `cpu_affinity`: Enable CPU affinity for workers (default: False)
|
|
275
|
-
|
|
276
|
-
- **Logging and Debugging**
|
|
277
|
-
- `debug`: Enable debug mode (default: False)
|
|
278
|
-
- `log_level`: Logging level (default: "INFO")
|
|
279
|
-
|
|
280
|
-
### Environment Variables
|
|
281
|
-
|
|
282
|
-
You can configure Pyarallel using environment variables with the `PYARALLEL_` prefix:
|
|
283
|
-
|
|
284
|
-
```bash
|
|
285
|
-
PYARALLEL_MAX_WORKERS=4
|
|
286
|
-
PYARALLEL_TIMEOUT=60.0
|
|
287
|
-
PYARALLEL_DEBUG=true
|
|
288
|
-
```
|
|
289
|
-
|
|
290
|
-
### Configuration Files
|
|
291
|
-
|
|
292
|
-
Load configuration from JSON, YAML, or TOML files:
|
|
293
|
-
|
|
294
|
-
```python
|
|
295
|
-
from pyarallel import PyarallelConfig
|
|
296
|
-
|
|
297
|
-
# Load from file
|
|
298
|
-
config = PyarallelConfig.from_file("pyarallel.yaml")
|
|
299
|
-
|
|
300
|
-
# Convert to dictionary
|
|
301
|
-
config_dict = config.to_dict()
|
|
401
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
@@ -19,10 +19,10 @@ def test_partial_update():
|
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
## 2. Environment Variables Support [✅]
|
|
22
|
-
- [] Add env var parsing in config manager
|
|
23
|
-
- [] Implement type coercion (str -> proper type)
|
|
24
|
-
- [] Add prefix support (PYARALLEL_*)
|
|
25
|
-
- [] Support complex values (lists, dicts via JSON)
|
|
22
|
+
- [✅] Add env var parsing in config manager
|
|
23
|
+
- [✅] Implement type coercion (str -> proper type)
|
|
24
|
+
- [✅] Add prefix support (PYARALLEL_*)
|
|
25
|
+
- [✅] Support complex values (lists, dicts via JSON)
|
|
26
26
|
|
|
27
27
|
**Test Cases:**
|
|
28
28
|
```python
|
|
@@ -37,10 +37,10 @@ def test_env_var_prefix():
|
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
## 3. Runtime Configuration API [✅]
|
|
40
|
-
- [] Add global `set()` method
|
|
41
|
-
- [] Add category-specific setters
|
|
42
|
-
- [] Add value getters with dot notation
|
|
43
|
-
- [] Implement config validation hooks
|
|
40
|
+
- [✅] Add global `set()` method
|
|
41
|
+
- [✅] Add category-specific setters
|
|
42
|
+
- [✅] Add value getters with dot notation
|
|
43
|
+
- [✅] Implement config validation hooks
|
|
44
44
|
|
|
45
45
|
**Test Cases:**
|
|
46
46
|
```python
|
|
@@ -55,10 +55,10 @@ def test_dot_notation():
|
|
|
55
55
|
```
|
|
56
56
|
|
|
57
57
|
## 4. Decorator Integration [✅]
|
|
58
|
-
- [] Update parallel decorator to use config
|
|
59
|
-
- [] Add config override in decorator
|
|
60
|
-
- [] Implement inheritance rules
|
|
61
|
-
- [] Add runtime config warnings
|
|
58
|
+
- [✅] Update parallel decorator to use config
|
|
59
|
+
- [✅] Add config override in decorator
|
|
60
|
+
- [✅] Implement inheritance rules
|
|
61
|
+
- [✅] Add runtime config warnings
|
|
62
62
|
|
|
63
63
|
**Test Cases:**
|
|
64
64
|
```python
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# API Reference
|
|
2
|
+
|
|
3
|
+
## Configuration API
|
|
4
|
+
|
|
5
|
+
### ConfigManager
|
|
6
|
+
|
|
7
|
+
Singleton class for managing global configuration.
|
|
8
|
+
|
|
9
|
+
```python
|
|
10
|
+
from pyarallel import ConfigManager
|
|
11
|
+
|
|
12
|
+
config_manager = ConfigManager.get_instance()
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
#### Methods
|
|
16
|
+
|
|
17
|
+
- `get_config()`: Get current configuration
|
|
18
|
+
- `update_config(config: dict)`: Update configuration with new values
|
|
19
|
+
- `reset_config()`: Reset to default configuration
|
|
20
|
+
|
|
21
|
+
#### Configuration Options
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
{
|
|
25
|
+
"execution": {
|
|
26
|
+
"default_max_workers": 4,
|
|
27
|
+
"default_executor_type": "thread",
|
|
28
|
+
"default_batch_size": 10
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
#### Examples
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
# Get config manager instance
|
|
37
|
+
config_manager = ConfigManager.get_instance()
|
|
38
|
+
|
|
39
|
+
# Update global configuration
|
|
40
|
+
config_manager.update_config({
|
|
41
|
+
"execution": {
|
|
42
|
+
"default_max_workers": 8,
|
|
43
|
+
"default_executor_type": "process"
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
# Get current configuration
|
|
48
|
+
config = config_manager.get_config()
|
|
49
|
+
```
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# API Reference
|
|
2
|
+
|
|
3
|
+
## Decorator API
|
|
4
|
+
|
|
5
|
+
### @parallel
|
|
6
|
+
|
|
7
|
+
The main decorator for enabling parallel execution of functions.
|
|
8
|
+
|
|
9
|
+
```python
|
|
10
|
+
from pyarallel import parallel
|
|
11
|
+
|
|
12
|
+
@parallel(
|
|
13
|
+
max_workers: int = None,
|
|
14
|
+
batch_size: int = None,
|
|
15
|
+
rate_limit: float | tuple[float, TimeUnit] | RateLimit = None,
|
|
16
|
+
executor_type: Literal["thread", "process"] = None,
|
|
17
|
+
prewarm: bool = False
|
|
18
|
+
)
|
|
19
|
+
def function(item, *args, **kwargs) -> Any: ...
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
#### Parameters
|
|
23
|
+
|
|
24
|
+
- `max_workers` (int, optional): Maximum number of parallel workers. Defaults to global configuration.
|
|
25
|
+
- `batch_size` (int, optional): Number of items to process in each batch. Defaults to global configuration.
|
|
26
|
+
- `rate_limit`: Rate limiting configuration. Can be:
|
|
27
|
+
- A float (operations per second)
|
|
28
|
+
- A tuple of (count, unit) where unit is "second", "minute", or "hour"
|
|
29
|
+
- A RateLimit instance
|
|
30
|
+
- `executor_type` (str, optional): Type of parallelism to use ("thread" or "process"). Defaults to global configuration.
|
|
31
|
+
- `prewarm` (bool): If True, starts all workers immediately.
|
|
32
|
+
|
|
33
|
+
#### Returns
|
|
34
|
+
|
|
35
|
+
A wrapped function that accepts either:
|
|
36
|
+
- A single item (returns a single-item list)
|
|
37
|
+
- A list/tuple of items (processes in parallel and returns a list of results)
|
|
38
|
+
|
|
39
|
+
#### Examples
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
# Basic usage with threads
|
|
43
|
+
@parallel(max_workers=4)
|
|
44
|
+
def fetch_url(url: str) -> dict:
|
|
45
|
+
return requests.get(url).json()
|
|
46
|
+
|
|
47
|
+
# Process-based execution with rate limiting
|
|
48
|
+
@parallel(
|
|
49
|
+
max_workers=4,
|
|
50
|
+
executor_type="process",
|
|
51
|
+
rate_limit=(100, "minute")
|
|
52
|
+
)
|
|
53
|
+
def process_image(image: bytes) -> bytes:
|
|
54
|
+
return heavy_processing(image)
|
|
55
|
+
|
|
56
|
+
# Batch processing with prewarming
|
|
57
|
+
@parallel(
|
|
58
|
+
max_workers=4,
|
|
59
|
+
batch_size=10,
|
|
60
|
+
prewarm=True
|
|
61
|
+
)
|
|
62
|
+
def analyze_text(text: str) -> dict:
|
|
63
|
+
return text_analysis(text)
|
|
64
|
+
```
|