Skip to main content

Tool for safe launching external processes

Project description

app_executor

This program might be used for launching external executables from python script. It can also collect stdout and stderr of them and store it into text file. In case of any failure it can also provide some basic stacktrace collection.

Importing app_executor package gives an access to two essential classes:

  • app_executor.Process - this class can be used for direct launching processes
  • app_executor.AppExecutor - this class can be used for automatic managing of launching multiple processes

Example usage

app_executor.Process

This code launches whoami and aliases it as MyName - all warning/error prints will be having this alias for increasing readability. Then it runs the process and waits up to 1 second for it to finish. In the end it prints result code and actual output (stdout and stderr combined) of executed command.

In the exit step command will be stopped (firstly app_executor.Process will try to terminate it and if that fails - kill it). And afterwards it will perform core dump analysis (if core dump was collected during the execution).

All result files - logs from gdb, process itself, core dump and stacktrace will be put into /some/path/MyName directory.

import app_executor
with app_executor.Process(name='MyName',
                          cmd='whoami',
                          parent_context_dir='/some/path') as process:
    process.run()
    if not process.wait(timeout=1):
        raise Exception('Process hanged for too long!')

    print('Returncode was: {}'.format(process.get_rc()))
    print('Output of whoami: {}'.format(process.get_logfile()))

app_executor.AppExecutor

This code works similar to former. Here execution path is passed once for all processes launched later on. app_executor.AppExecutor can either assign aliases by itself (process_1, process_2, etc.) or user can set them manually.

run function returns app_executor.Process object that can be used to interact with the process later on (similarly as in former example).

In the exit step app_executor.AppExecutor will stop every child process and perform dump analysis if core dump were collected. All result files will be stored under the path /some/path/$NAME_OF_THE_PROCESS.

import app_executor
with app_executor.AppExecutor('/some/path') as executor:
    p1 = executor.run('whoami')
    p2 = executor.run('sleep 1', 'MyCustomAlias')

    # ...
    # operations on p1 and p2 app_executor.Process objects
    # ...

executor fixture

Together with installing app_executor package executor pytest fixture becomes available. It creates app_executor.AppExecutor and passes tmpdir as work directory to it. On fixture teardown all spawned processes are stopped.

def test_some_executing(executor):
    p1 = executor.run('whoami')
    p2 = executor.run('sleep 1')

    # ...
    # operations on p1 and p2 app_executor.Process objects
    # ...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

app_executor-1.0.4.tar.gz (5.8 kB view details)

Uploaded Source

File details

Details for the file app_executor-1.0.4.tar.gz.

File metadata

  • Download URL: app_executor-1.0.4.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/3.6.7

File hashes

Hashes for app_executor-1.0.4.tar.gz
Algorithm Hash digest
SHA256 dc324231fdf78a0bc2c3e68d16f3c3be82ef661ef2fe31694bfbec41bb2e87dd
MD5 7dcde5a406029f2a3ee45908cdf09161
BLAKE2b-256 619cc3674cc98145eb9404744321a6c0d00ef58c6009220a042d45e8bb61d81f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page