Skip to main content

Command Spawner

Project description

Python package License: MIT

Command Spawner

Command Spawner is a non-blocking command runner library for Python.

Command Spawner runs commands at background and provides live output, error and finish data through the provided callback functions.

Installing

Install and update using pip:

$ pip install command-spawner

Example usage

# Triggered when received new stdout
def on_output(data):
    print(f"Received data: {data}")


# Triggered when received new stderr
def on_error(data):
    print(f"Received error: {data}")


# Triggered when the command execution has finished
def on_finished(data):
    print(f"Finished with return code: {data}")


# Triggered when an exception has been thrown from the process module
def on_exception(exception):
    print(f"Received exception: {exception}")
    # or
    raise exception


command_spawner = CommandSpawner(command="ping google.com",
                                 on_output_callback=on_output,  # Suppress output when it is not provided
                                 on_error_callback=on_error,  # Suppress error when it is not provided
                                 on_finished_callback=on_finished,  # Suppress return code when it is not provided
                                 on_exception_callback=on_exception,  # Raise exception on runtime when it is not provided
                                 shell=False,  # If True, the command will be executed through the shell (not recommended)
                                 daemon=False  # If True, current runtime will not wait for commands to be executed 
                                 )

# The method to run the process
command_spawner.run()

# The method to kill the current process
command_spawner.kill()

# The method to wait for the process to be finished
command_spawner.wait()

Enjoy!

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

command_spawner-1.1.3.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

command_spawner-1.1.3-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file command_spawner-1.1.3.tar.gz.

File metadata

  • Download URL: command_spawner-1.1.3.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.5

File hashes

Hashes for command_spawner-1.1.3.tar.gz
Algorithm Hash digest
SHA256 eb9ee75d6dd7053a655f0d68d4167606525aee25de492ac71bf36f9b666ac6b1
MD5 b9ece0924b2d809083e6a97cec20535c
BLAKE2b-256 18b81f12dd7b8d12d74a76b2e00ea178bc270d700ce459864145eab555fd3488

See more details on using hashes here.

File details

Details for the file command_spawner-1.1.3-py3-none-any.whl.

File metadata

  • Download URL: command_spawner-1.1.3-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.5

File hashes

Hashes for command_spawner-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2996f7e9ca35e8ee78279fef18b22810175652a0984c0a6cb46b7cab045bbc2f
MD5 66ba07f84d097119dac2d06be10ec12a
BLAKE2b-256 2f8e494374ef33cb59a340a026f941d45c7d31f1a8d11cfb01a7a7b476c3e8dd

See more details on using hashes here.

Supported by

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