Skip to main content

bglaunch

Start Python training jobs in the background on one machine, with a hard limit on how many cores they may use.

launchJob takes a Python file and a configuration, starts it in a separate process, and returns one line of text saying what happened. It does not import your code, so the job can be any script that takes one config argument.

Each job is a fresh interpreter started by the shell (fork followed by exec), so nothing CUDA-related is inherited from the caller. That is the pattern NVIDIA allows: a forked child must exec before it touches the driver. The alternative, forking a process that already holds a CUDA context, is what produces the Cannot re-initialize CUDA in forked subprocess failures.

Install

pip install git+https://github.com/SmellingSalt/bglaunch

Or from a clone of this repository:

pip install .

Use it

from bglaunch import launchJob

print(launchJob(pythonFile="train.py", config="config.yaml"))
launched pythonFile "train.py" with config config.yaml with 1 thread(s), PID 27930 log logs/config.log

threads is optional and defaults to 1. It sets OMP_NUM_THREADS and MKL_NUM_THREADS for the job and counts the same number against the core budget. It does not pin cores; a script that ignores those variables can still use more than it asked for.

The bash script is the same API one level down, if you would rather not use Python at all:

bash bglaunch/launchParallel.sh train.py config.yaml -threads 1

The package is two files plus examples:

bglaunch/launchJob.py        launchJob(...), the API
bglaunch/launchParallel.sh   the engine: core budget, logs, pid registry
bglaunch/examples/           delayExample.py, delay.py, configs/

What a launch guarantees

  • The job runs in the background; the call returns in milliseconds.
  • logs/<config name>.log holds its stdout and stderr.
  • logs/pids.txt gains a pid threads config row.
  • At most CPUS - 1 cores are handed out across all jobs, so one core always stays free. A launch that would take the last one is refused instead of oversubscribing the machine.
  • Finished jobs are dropped from the registry on the next launch. A pid reused by an unrelated process does not hold cores, because the registry entry only counts while the live command line still ends in the same config.

Exit codes, if you call the script yourself: 0 started, 2 bad arguments, 3 no free core left. launchJob turns all of them into text.

Example

examples/delay.py sleeps for the number of seconds in its config and records when it started and finished. examples/configs/ has five delays (2, 10, 15, 26, 32 seconds); the demo below runs two of them.

python3 -m bglaunch.examples.delayExample
launched pythonFile "./delay.py" with config configs/delay_02.yaml with 1 thread(s), PID 29631 log logs/delay_02.log
launched pythonFile "./delay.py" with config configs/delay_10.yaml with 1 thread(s), PID 29641 log logs/delay_10.log

The example switches to its own folder first, so the logs land in bglaunch/examples/logs/ when you run it from a clone. Each job also writes results/delayTest/<config name>/timing.txt next to it, so one folder per job shows up in the shell.

Watching a batch

cat logs/pids.txt        # what is running: pid, threads, config
tail -f logs/*.log       # live output of every job

To check per-job cpu use, for instance when judging the thread count, ask ps for those pids. Linux:

ps -o pid,psr,pcpu,etime -p $(awk -F'\t' 'NR>1{print $1}' logs/pids.txt | paste -sd, -)

psr is the cpu a job ran on. macOS has no psr column, so drop it there.

Limits

  • The launcher reports whether a job started, not whether it succeeded. Outcomes are in the logs.
  • The log name is the config filename without its extension, so relaunching the same config overwrites its log.
  • Jobs survive the process that launched them; stopping them means killing the pids in logs/pids.txt.
  • Paths resolve against the caller's working directory, and so do the logs/ and results/ folders the jobs write.
  • Tested on Linux and macOS. Windows is not supported, because the launcher is a bash script.

Metadata

Release files for bglaunch 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bglaunch 0.1.0
File Size Uploaded Provenance Actions
bglaunch-0.1.0.tar.gz 9.7 kB Without provenance Details for bglaunch-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bglaunch 0.1.0
File Interpreter ABI Platform Actions
bglaunch-0.1.0-py3-none-any.whl Python 3 none any Details for bglaunch-0.1.0-py3-none-any.whl

Total release size: 19.7 kB

Release files / bglaunch-0.1.0.tar.gz

Download URL bglaunch-0.1.0.tar.gz
Size 9.7 kB
Tags Source
SHA-256 checksum
How to use checksums
95dcb0f31e9b46ca75838bf62599d50f540b5d42231da898c224e974e451df5f
BLAKE2b-256 checksum
How to use checksums
127b7269c24231394cf3c9996116bd7cce32c5abba3511ac173f481d4af6b46f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.3

Release files / bglaunch-0.1.0-py3-none-any.whl

Download URL bglaunch-0.1.0-py3-none-any.whl
Size 10.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b9176c76802e3fbcdd303c2e4fa5a2be710cc91dbac174a144944d89cf340823
BLAKE2b-256 checksum
How to use checksums
9fb1d70b69581abae457201badca8fe7b8e5241775ca49655e1ef44792b996ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.3

Security for bglaunch 0.1.0

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page