Skip to main content

Establish a connection to the errand-boy deamon to execute commands without the memory overhead incurred by os.fork().

Project description

https://travis-ci.org/SeanHayes/errand-boy.svg?branch=master https://coveralls.io/repos/SeanHayes/errand-boy/badge.png?branch=master

What does it do?

Uses Python multiprocessing to maintain a pool of worker processes used to execute arbitrary terminal commands.

Why not use subprocess.Popen()?

Under the hood subprocess.Popen() uses os.fork(), which copies the currently running process’ memory before launching the command you want to run. If your process uses a lot of memory, such as a Celery worker using an eventlet pool, this can cause a “Cannot allocate memory” error.

errand-boy still uses subprocess.Popen(), but tries to keep a low memory footprint. Your celery greenthread workers can communicate with it via asynchronous network calls.

Further reading:

  1. http://stackoverflow.com/a/13329386/241955

  2. http://stackoverflow.com/a/14942111/241955

Setup

Install:

pip install errand-boy

# optional pip install setproctitle

Usage

Run tests:

cd errand-boy/
python -m unittest discover

Run server:

python -m errand_boy.run

Run client (useful for testing/debugging):

python -m errand_boy.run 'ls -al'

Use the client in your code:

from errand_boy.transports.unixsocket import UNIXSocketTransport


errand_boy_transport = UNIXSocketTransport()

stdout, stderr, returncode = errand_boy_transport.run_cmd('ls -al')

print stdout
print stderr
print returncode

Use a subprocess.Popen-like interface:

from errand_boy.transports.unixsocket import UNIXSocketTransport


errand_boy_transport = UNIXSocketTransport()

# Attribute accesses and function calls on objects retrieved via a session
# result in a call to the errand-boy server, unless that object is a string
# or number type.
with errand_boy_transport.get_session() as session:
    subprocess = session.subprocess

    # Here, subprocess.Popen is actually a reference to the actual objects
    # on the errand-boy server. subprocess.PIPE is an int.
    process = subprocess.Popen('ls -al', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, close_fds=True)

    # Here, process_stdout and process_stderr are strings and returncode is
    # an int, so their actual values are returned instead of references to
    # the remote objects. This means it's safe to use these values later on
    # outside of the current session.
    process_stdout, process_stderr = process.communicate()
    returncode = process.returncode

print stdout
print stderr
print returncode

# Since the session has been closed, trying this will result in an error:
print process.returncode
# raised errand_boy.exceptions.SessionClosedError()

Run load tests:

python -m errand_boy.run --max-accepts=0

pip install Fabric locustio
cd errand-boy/
fab locust_local

Does it work in other languages?

The client/server use an HTTP-inspired protocol, but the data that’s sent back and forth is currently serialized using Python’s Pickle format. Support could be added for other serialization types though.

Development

Further reading:

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

errand-boy-0.3.7.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

errand_boy-0.3.7-py2-none-any.whl (14.9 kB view details)

Uploaded Python 2

File details

Details for the file errand-boy-0.3.7.tar.gz.

File metadata

  • Download URL: errand-boy-0.3.7.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for errand-boy-0.3.7.tar.gz
Algorithm Hash digest
SHA256 ac91636413fb57745dee403fb1e2766dcf7ff344bd3ee186b24e5a7c8ce25489
MD5 f5096e7b569216812884f708afbc2ad5
BLAKE2b-256 5c282c4446a08622b2ffbdbaac1511d61087a8aea9b16ab7182c2e3d94ff0299

See more details on using hashes here.

File details

Details for the file errand_boy-0.3.7-py2-none-any.whl.

File metadata

File hashes

Hashes for errand_boy-0.3.7-py2-none-any.whl
Algorithm Hash digest
SHA256 90edb2513bce9bb5b09623a07502b085b8fe23b69026bca88273b54288159325
MD5 ba2841a2fba76de8220848ac98b25fa6
BLAKE2b-256 ac612cea8950db0bf75dca6e0f4e31d8e89137b4dc5147450683d18873277356

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