Run multiple subprocesses asynchronous/in parallel with streamed output/non-blocking reading. Also various tools to replace shell scripts.
Project description
shelljob
This provides a clean way to execute subprocesses, either one or multiple in parallel, capture their output and monitor progress:
- Single sub process
call
with optional timeout - High level
FileMonitor
to execute several processes in parallel and store output in a file - Low level
Group
execution to execute jobs in parallel and capture output
Additional tools for working with the filesystem are also included:
find
which offers much of the functionality of the shell find utilityshelljob.fs.NamedTempFile
provides a with block wrapper for temporary named files
Install
pip install shelljob
Parallel Subprocesses
Using the Job system is the quickest approach to just run processes and log their output (by default in files named '/tmp/job_ID.log')
from shelljob import job
jm = job.FileMonitor()
jm.run([
[ 'ls', '-alR', '/usr/local' ],
'my_prog',
'build output input',
])
An array will passed directly to subprocess.Popen
, a string is first parsed with shlex.split
.
The lower level Group
class provides a simple container for more manual job management.
from shelljob import proc
g = proc.Group()
p1 = g.run( [ 'ls', '-al', '/usr/local' ] )
p2 = g.run( [ 'program', 'arg1', 'arg2' ] )
while g.is_pending():
lines = g.readlines()
for proc, line in lines:
sys.stdout.write( "{}:{}".format( proc.pid, line ) )
Simple Subprocess calls
A simplified call
function allows timeouts on subprocesses and easy acces to their output.
from shelljob import proc
# capture the output
output = proc.call( 'ls /tmp' )
# this raises a proc.Timeout exception
proc.call( 'sleep 10', timeout = 0.1 )
Find
The 'find' funtion is a multi-faceted approach to generating listings of files.
from shelljob import fs
files = fs.find( '/usr/local', name_regex = '.*\\.so' )
print( "\n".join(files) )
Refer to the API docs for all parameters. Just let me know if there is some additional option you need.
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
File details
Details for the file shelljob-0.6.tar.gz
.
File metadata
- Download URL: shelljob-0.6.tar.gz
- Upload date:
- Size: 16.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e3afedacba48fedccce37772f75deac8ad0c9b500617edc8a5234c725f0d52f |
|
MD5 | 23c9fdeeaa5af2286d029706a939261e |
|
BLAKE2b-256 | cffa5dac506647e483fdd51995b12d9d5411e0dead1c04011d31360dceca5ecd |
File details
Details for the file shelljob-0.6-py3-none-any.whl
.
File metadata
- Download URL: shelljob-0.6-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19ca3a5a6b9c575d2b82456c4f8dd12cebcf5d719a0ec46b96c811bce73c717e |
|
MD5 | b2d7869a49cedd9fc11c40d8cf3365bf |
|
BLAKE2b-256 | 50d2ecb26a4f9b14e95b85f72b16e03f18dc6f305f4d0115ca831e909aa8f586 |