Skip to main content

EasyProcess is an easy to use python subprocess interface.

Links:

Travis Coveralls Latest Version Supported Python versions License Code Health Documentation

Features:
  • layer on top of subprocess module

  • easy to start, stop programs

  • easy to get standard output/error, return code of programs

  • command can be list (preferred) or string (command string is converted to list using shlex.split)

  • logging

  • timeout

  • unit-tests

  • cross-platform, development on linux

  • shell is not supported

  • pipes are not supported

  • stdout/stderr is set only after the subprocess has finished

  • stop() does not kill whole subprocess tree

  • unicode support

  • supported python versions: 2.7, 3.5, 3.6, 3.7, 3.8

  • Method chaining

Similar projects:

Basic usage

>>> from easyprocess import EasyProcess
>>> EasyProcess('python --version').call().stderr
u'Python 2.6.6'

Installation

install:

pip install EasyProcess

uninstall:

pip uninstall EasyProcess

Usage

Simple example

Example program:

#-- include('examples/hello.py')--#
from easyprocess import EasyProcess
import sys

s = EasyProcess([sys.executable, '-c', 'print "hello"']).call().stdout
print(s)
#-#

Output:

#-- sh('python -m easyprocess.examples.hello')--#
hello
#-#

General

The command can be a string list or a concatenated string:

#-- include('examples/cmd.py')--#
from easyprocess import EasyProcess

print('-- Run program, wait for it to complete, get stdout (command is string):')
s=EasyProcess('python -c "print 3"').call().stdout
print(s)

print('-- Run program, wait for it to complete, get stdout (command is list):')
s=EasyProcess(['python','-c','print 3']).call().stdout
print(s)

print('-- Run program, wait for it to complete, get stderr:')
s=EasyProcess('python --version').call().stderr
print(s)

print('-- Run program, wait for it to complete, get return code:')
s=EasyProcess('python --version').call().return_code
print(s)

print('-- Run program, wait 1 second, stop it, get stdout:')
s=EasyProcess('ping localhost').start().sleep(1).stop().stdout
print(s)

#-#

Output:

#-- sh('python -m easyprocess.examples.cmd')--#
-- Run program, wait for it to complete, get stdout (command is string):
3
-- Run program, wait for it to complete, get stdout (command is list):
3
-- Run program, wait for it to complete, get stderr:
Python 2.7.6
-- Run program, wait for it to complete, get return code:
0
-- Run program, wait 1 second, stop it, get stdout:
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.017 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.034 ms
#-#

Shell commands

Shell commands are not supported.

return_code

EasyProcess.return_code is None until EasyProcess.stop or EasyProcess.wait is called.

With

By using with statement the process is started and stopped automatically:

from easyprocess import EasyProcess
with EasyProcess('ping 127.0.0.1') as proc: # start()
    # communicate with proc
    pass
# stopped

Equivalent with:

from easyprocess import EasyProcess
proc = EasyProcess('ping 127.0.0.1').start()
try:
    # communicate with proc
    pass
finally:
    proc.stop()

Timeout

This was implemented with “daemon thread”.

“The entire Python program exits when only daemon threads are left.” http://docs.python.org/library/threading.html:

#-- include('examples/timeout.py')--#
from easyprocess import EasyProcess

s = EasyProcess('ping localhost').call(timeout=2).stdout
print(s)
#-#

Output:

#-- sh('python -m easyprocess.examples.timeout')--#
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.018 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.037 ms
64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.025 ms
#-#

Replacing existing functions

Replacing os.system:

retcode = os.system("ls -l")
==>
p = EasyProcess("ls -l").call()
retcode = p.return_code
print(p.stdout)

Replacing subprocess.call:

retcode = subprocess.call(["ls", "-l"])
==>
p = EasyProcess(["ls", "-l"]).call()
retcode = p.return_code
print(p.stdout)

Metadata

Release files for EasyProcess 0.2.9

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

Source distribution (sdist)

Source distribution for EasyProcess 0.2.9
File Size Uploaded Provenance Actions
EasyProcess-0.2.9.tar.gz 48.6 kB Without provenance Details for EasyProcess-0.2.9.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for EasyProcess 0.2.9
File Interpreter ABI Platform Actions
EasyProcess-0.2.9-py2.py3-none-any.whl Python 2, Python 3 none any Details for EasyProcess-0.2.9-py2.py3-none-any.whl

Total release size: 58.8 kB

Release files / EasyProcess-0.2.9.tar.gz

Download URL EasyProcess-0.2.9.tar.gz
Size 48.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ddb7a425bc68936fb2ca91fa5ab385da3b58cd10c9134fa26f5210be5dbf47c6
BLAKE2b-256 checksum
How to use checksums
302db8afe262637636f27ec45af5792585d756b8f55380e657d5681d265d41c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/2.7.17

Release files / EasyProcess-0.2.9-py2.py3-none-any.whl

Download URL EasyProcess-0.2.9-py2.py3-none-any.whl
Size 10.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
ec8043ca3ac1544a665189cf779ae7f8049654e050fcf389548b2e183c0ac98c
BLAKE2b-256 checksum
How to use checksums
3d479559808446353ef6436c13e7b1475f90ce068e89c600add1c8f219063fcc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/2.7.17

Security for EasyProcess 0.2.9

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.

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