bombsquad
Isolate OOM-prone functions in a separate process, raise exceptions on SIGKILL or segfault.
Methods that cause out-of-memory errors (OOM) or segfaults are killed by the OS immediately, crashing the interpreter without raising an exception.
To solve this problem, the bombsquad package provides the @bombsquad decorator. This runs the decorated function in a separate, isolated process. If that process is terminated by the OS (e.g. SIGKILL), bombsquad catches the exit code and raises a NonzeroExitcode exception in your main process.
Normal Python exceptions raised within the function are propagated back to the parent process transparently.
Installation
pip install bombsquad
Quick Start
1. Trapping a Crash
Protect your main application from dangerous functions.
import os
import signal
from bombsquad import bombsquad, NonzeroExitcode
@bombsquad
def risky_business():
print("Running risky code...")
# Simulate a hard crash (like an OOM killer)
os.kill(os.getpid(), signal.SIGKILL)
try:
risky_business()
except NonzeroExitcode as e:
print(f"Caught crash! Process exited with code {e.exitcode}")
2. Propagating Exceptions
Standard exceptions work exactly as expected.
@bombsquad
def divide(a, b):
return a / b
try:
divide(10, 0)
except ZeroDivisionError:
print("Caught division by zero from child process.")
Advanced Configuration
The decorator accepts arguments to tune performance and safety.
@bombsquad(start_method="spawn", backend="file")
def massive_processing(data):
...
Parameters
| Argument | Options | Default | Description |
|---|---|---|---|
start_method |
"spawn", "fork" |
"spawn" |
How the child process is created. |
backend |
"file", "queue" |
"file" |
How data is returned to the parent. |
Choosing a backend
-
"file"(Default, Recommended):- Mechanism: Serializes results to a temporary file on disk.
- Pros: Supports unlimited return sizes (limited only by disk space).
- Cons: Slower due to disk I/O.
- Use for: Returning large arrays, datasets, or huge strings.
-
"queue":- Mechanism: Uses
multiprocessing.Queue(memory pipes). - Pros: Faster (in-memory transfer).
- Cons: Limited to ~4GB payloads (Python pickle limit).
- Use for: Returning small results (status codes, metrics, small dicts).
- Mechanism: Uses
License
MIT
Metadata
Release files for bombsquad 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bombsquad-0.1.2.tar.gz | 4.5 kB | Without provenance | Details for bombsquad-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bombsquad-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for bombsquad-0.1.2-py3-none-any.whl |
Total release size: 10.0 kB
Release files / bombsquad-0.1.2.tar.gz
| Download URL | bombsquad-0.1.2.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a836a7813d28afb3d11489225779fff540409a418631110ecdae955292830165
|
|
BLAKE2b-256 checksum How to use checksums |
ee7480f3c3bc179d743d8db1715419fb29283ac4e545b8a43ee50106ad9363cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.9
|
Release files / bombsquad-0.1.2-py3-none-any.whl
| Download URL | bombsquad-0.1.2-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3f5fe8b7e5003c41b55b5b0b4d98c4187cba11c55f8958abbfa8eca3d19171ef
|
|
BLAKE2b-256 checksum How to use checksums |
177641b747c17151fdda9e30dfe315a642e710303f8b3f6db28e17706a88094a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.9
|
Security for bombsquad 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.