Skip to main content

Process pool with hard-kill timeouts and import warming

Project description

warmpool

A single-worker subprocess pool that can kill C extensions.

PyPI License Python


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, etc which 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

warmpool-0.1.2.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

warmpool-0.1.2-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

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

Hashes for warmpool-0.1.2.tar.gz
Algorithm Hash digest
SHA256 890e6a77b6ea6a4682021a1d81e7c7f27dff70c5839c7393512bd74f00a9bf04
MD5 fd3ffaf7d64517ad5a5249294e388939
BLAKE2b-256 4444b44d6282ac9144eeec54eb46619f86d4fa35ff035f4fc85ec1cb86027e06

See more details on using hashes here.

Provenance

The following attestation bundles were made for warmpool-0.1.2.tar.gz:

Publisher: ci.yml on slopden/warmpool

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for warmpool-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8b2bf2ee25a76414532e619ef2c0668e1e0d6feb3c2849b984d053b8e7902580
MD5 ff7af3ca8a07822593f16c78bb2e443b
BLAKE2b-256 0b861e09c6db132355608d967dcfa42db1bfade3de378af3b3f98bfe725df1af

See more details on using hashes here.

Provenance

The following attestation bundles were made for warmpool-0.1.2-py3-none-any.whl:

Publisher: ci.yml on slopden/warmpool

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page