Process pool with hard-kill timeouts and import warming
Project description
A single-worker subprocess pool that can kill C extensions.
A "ProcessPool-like-executor" with hard-kill timeouts and import warming. The basic problem is that if you freeze up deep in a C-extension Python timeout-handling stuff doesn't work. warmpool runs functions in a spawned subprocess, and if they exceed their timeout it SIGTERM+SIGKILL the process and all children if the C extension has spawned anything.
- It calls a "warming function" in each new process, so you can have it keep a process warmed with
import scipy, numpy, etcwhich can easily be 2+ seconds. - The timeouts actually work regardless of what happens in the function.
- It has an option to keep a spare process warm in the background so it can rotate cleanly without eating an import period.
- It sends logs back to the parent through a pipe.
import time
from warmpool import WarmPool
def warm_imports():
import numpy
import scipy.linalg
def eigh_huge(n=5000):
"""Stuck in LAPACK C code — only SIGKILL works."""
import numpy as np
from scipy import linalg
a = np.random.rand(n, n)
a = a + a.T
return linalg.eigh(a)
def add(a=0, b=0):
return a + b
pool = WarmPool(warming=warm_imports)
# numpy+scipy are already imported — no 2s wait
start = time.perf_counter()
try:
pool.run(eigh_huge, timeout=0.5, n=5000)
except TimeoutError:
print(f"killed after {time.perf_counter() - start:.2f}s")
# pool recovered via spare
result = pool.run(add, timeout=5.0, a=2, b=3)
print(f"recovered: add(2, 3) = {result}")
pool.shutdown()
killed after 0.53s
recovered: add(2, 3) = 5
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 warmpool-0.1.2.tar.gz.
File metadata
- Download URL: warmpool-0.1.2.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
890e6a77b6ea6a4682021a1d81e7c7f27dff70c5839c7393512bd74f00a9bf04
|
|
| MD5 |
fd3ffaf7d64517ad5a5249294e388939
|
|
| BLAKE2b-256 |
4444b44d6282ac9144eeec54eb46619f86d4fa35ff035f4fc85ec1cb86027e06
|
Provenance
The following attestation bundles were made for warmpool-0.1.2.tar.gz:
Publisher:
ci.yml on slopden/warmpool
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
warmpool-0.1.2.tar.gz -
Subject digest:
890e6a77b6ea6a4682021a1d81e7c7f27dff70c5839c7393512bd74f00a9bf04 - Sigstore transparency entry: 1519959490
- Sigstore integration time:
-
Permalink:
slopden/warmpool@1ed63d7401cf2bc7135e6a4cecfb035317601a49 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/slopden
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@1ed63d7401cf2bc7135e6a4cecfb035317601a49 -
Trigger Event:
push
-
Statement type:
File details
Details for the file warmpool-0.1.2-py3-none-any.whl.
File metadata
- Download URL: warmpool-0.1.2-py3-none-any.whl
- Upload date:
- Size: 13.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b2bf2ee25a76414532e619ef2c0668e1e0d6feb3c2849b984d053b8e7902580
|
|
| MD5 |
ff7af3ca8a07822593f16c78bb2e443b
|
|
| BLAKE2b-256 |
0b861e09c6db132355608d967dcfa42db1bfade3de378af3b3f98bfe725df1af
|
Provenance
The following attestation bundles were made for warmpool-0.1.2-py3-none-any.whl:
Publisher:
ci.yml on slopden/warmpool
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
warmpool-0.1.2-py3-none-any.whl -
Subject digest:
8b2bf2ee25a76414532e619ef2c0668e1e0d6feb3c2849b984d053b8e7902580 - Sigstore transparency entry: 1519959526
- Sigstore integration time:
-
Permalink:
slopden/warmpool@1ed63d7401cf2bc7135e6a4cecfb035317601a49 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/slopden
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@1ed63d7401cf2bc7135e6a4cecfb035317601a49 -
Trigger Event:
push
-
Statement type: