singlesp.py
The Single Subprocess usage module.
Author: Moises P. Sena moisespsena@gmail.com
License: MIT
Examples
from singlesp import *
Instantiate
p = Proc('date')
# or
p = Proc(['echo', __file__])
stdout
For set stdout callback, use the > operator.
print(p.read())
# or
print(p.wait().read())
# or
print(p.run().wait().read())
def cb_out(proc):
for line in proc.out:
print("STDOUT: %r" % line)
Proc('date', callbacks=[cb_out]).wait()
def cb_outreader(reader):
for line in reader:
print("STDOUT: %r" % line)
(Proc('date') > cb_outreader).wait()
# or
p = Proc('date') > cb_outreader
p.wait()
buffer
def cb_outreader(reader):
for data in reader(10):
print("STDOUT: %r" % data)
(Proc('date') > cb_outreader).wait()
stderr
For set stderr callback, use the >> operator.
def cb_errreader(reader):
for data in reader:
print("ERR: %r" % data)
(Proc('date') >> cb_outreader).wait()
stdout and stderr callbacks
def cbo(reader):
for data in reader:
print("OUT: %r" % data)
def cbe(reader):
for data in reader:
print("ERR: %r" % data)
(Proc('echo out data;echo err data >&2;') > cbo >> cbe).wait()
callbacks
# async read stdout and stderr
def cb_stdout(proc):
for line in proc.out:
print("STDOUT: %r" % line)
def cb_stderr(proc):
for line in proc.err:
print("STDERR: %r" % line)
Proc('seq 1 3 | while read l; do echo "i= $l"; echo "i in err: $l" >&2; done',
callbacks=[cb_stdout, cb_stderr]).wait()
Many commands async
Proc('echo CMD-1: first command with sleep 1; sleep 1; echo CMD-1: done',
callbacks=[cb_stdout, cb_stderr]).run()
Proc('echo CMD-2: show date; date; echo CMD-2: done',
callbacks=[cb_stdout, cb_stderr]).run()
# wait all callbacks
print("before wait")
wait()
print("done")
Get exit status
p = Proc('date').run().wait()
# or p = Proc('date').wait()
print(p.status)
Pipes
Simple:
(Input(['God ', 'is ', 'Love!!']) | Proc(['cat'])).read()
def cb_stdout(reader):
for line in reader:
print("STDOUT: %r" % line)
p = Proc('seq 1 3') | Proc('grep 2') > cb_stdout
# or p = Proc('seq 1 3').pipe(Proc('grep 2')) > cb_stdout
p.run()
wait()
print(Input(['God ', 'is ', 'Love!!']) | Proc(['cat'])).read()
def gen():
yield 'God '
yield 'is '
yield 'Love!!'
print(Input(gen()) | Proc(['cat'])).read()
print(Commands(['date']) | Proc(['bash'])).read()
print(Commands(['date']) | bash()).read()
print(Commands(['date']) | sh()).read()
wait()
Simple:
p = Proc('seq 1 3') | Proc('grep 2') > cb_stdout
p.run()
wait()
Complex:
def cb_stdout(proc):
for line in proc.out:
print("STDOUT: %r" % line)
def a_stderr(proc):
for line in proc.err:
print("A-STDERR: %r" % line)
def b_stderr(proc):
for line in proc.err:
print("B-STDERR: %r" % line)
p = Proc('echo "[A] error message" >&2;seq 1 3', callbacks=[a_stderr]) | \
Proc('while read l; do echo "i= $l"; echo "[B] i in err: $l" >&2; done',
callbacks=[cb_stdout, b_stderr])
p.run()
wait()
Metadata
Release files for singlesp 1.0.1
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 |
|---|---|---|---|---|
| singlesp-1.0.1.tar.gz | 5.3 kB | Without provenance | Details for singlesp-1.0.1.tar.gz |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| singlesp-1.0.1-py3.4.egg | Legacy Egg format | - | - | Details for singlesp-1.0.1-py3.4.egg |
| singlesp-1.0.1-py2.7.egg | Legacy Egg format | - | - | Details for singlesp-1.0.1-py2.7.egg |
Total release size: 24.5 kB
Release files / singlesp-1.0.1.tar.gz
| Download URL | singlesp-1.0.1.tar.gz |
|---|---|
| Size | 5.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c6f899e760979047e64112f53ade9e6c05474a09ff1dd353d0c461dfe7c27cd4
|
|
BLAKE2b-256 checksum How to use checksums |
f2234b2b6646aace8e730fa2b3579cc354586a485167daa658852ea430e6c05f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / singlesp-1.0.1-py3.4.egg
| Download URL | singlesp-1.0.1-py3.4.egg |
|---|---|
| Size | 9.8 kB |
| Tags | Egg |
|
SHA-256 checksum How to use checksums |
4dae8b1101d07b0bde65287f8161a7f7f162c24c3e7fba8961dd294062edf6ac
|
|
BLAKE2b-256 checksum How to use checksums |
efd2a4e5acf32b668e04c7ee212c02fafd0fc7cbbbb2042b5222d180e5602da1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / singlesp-1.0.1-py2.7.egg
| Download URL | singlesp-1.0.1-py2.7.egg |
|---|---|
| Size | 9.4 kB |
| Tags | Egg |
|
SHA-256 checksum How to use checksums |
710ce5f5f34863873b687bbe84d05593880963dba7d953e5d231a36d82059417
|
|
BLAKE2b-256 checksum How to use checksums |
3b46484a30fa5d8740532d585e3961151e7b9bf21e3ab4e7378ddce13c5f8bbb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for singlesp 1.0.1
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.