Giter Club home page Giter Club logo

command_spawner's Introduction

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!

command_spawner's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.