All Projects → greyside → Errand Boy

greyside / Errand Boy

Licence: bsd-3-clause
A memory-conscious alternative to os.fork() and subprocess.Popen().

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Errand Boy

Shellrb
A unix-like shell built in Ruby
Stars: ✭ 24 (-29.41%)
Mutual labels:  unix
Bingehack4
A replacement for bingehack. For information about in-game features and changes:
Stars: ✭ 14 (-58.82%)
Mutual labels:  fork
Illumos Gate
An open-source Unix operating system
Stars: ✭ 952 (+2700%)
Mutual labels:  unix
Go Extend
go语言扩展包,收集一些常用的操作函数,辅助更快的完成开发工作,并减少重复代码
Stars: ✭ 839 (+2367.65%)
Mutual labels:  pool
Sortpem
➿ Sorting utility for PEM files
Stars: ✭ 11 (-67.65%)
Mutual labels:  unix
Notes
📝 Simple delightful note taking, with more unix and less lock-in.
Stars: ✭ 939 (+2661.76%)
Mutual labels:  unix
The Unix Workbench
🏡 A Book for Anyone to Get Started with Unix
Stars: ✭ 919 (+2602.94%)
Mutual labels:  unix
Glfw
A multi-platform library for OpenGL, OpenGL ES, Vulkan, window and input
Stars: ✭ 8,416 (+24652.94%)
Mutual labels:  unix
Fork Awesome
A fork of the iconic font and CSS toolkit
Stars: ✭ 878 (+2482.35%)
Mutual labels:  fork
Je
A distributed job execution engine for the execution of batch jobs, workflows, remediations and more.
Stars: ✭ 30 (-11.76%)
Mutual labels:  unix
Fotix
My very own UNIX clone, for education/self-amusement.
Stars: ✭ 8 (-76.47%)
Mutual labels:  unix
Cpp redis
C++11 Lightweight Redis client: async, thread-safe, no dependency, pipelining, multi-platform - NO LONGER MAINTAINED - Please check https://github.com/cpp-redis/cpp_redis
Stars: ✭ 855 (+2414.71%)
Mutual labels:  unix
Goridge
High-performance PHP-to-Golang IPC bridge
Stars: ✭ 950 (+2694.12%)
Mutual labels:  unix
Sralloc
Memory allocators
Stars: ✭ 25 (-26.47%)
Mutual labels:  memory-management
My Favorite Things
Moved to: https://gitlab.com/brennovich/my-favorite-things
Stars: ✭ 30 (-11.76%)
Mutual labels:  unix
Cxxhttp
Asynchronous, Header-only C++ HTTP-over-(TCP|UNIX Socket|STDIO) Library
Stars: ✭ 24 (-29.41%)
Mutual labels:  unix
Lab
Lab wraps Git or Hub, making it simple to clone, fork, and interact with repositories on GitLab
Stars: ✭ 911 (+2579.41%)
Mutual labels:  fork
Posnk
An operating system project.
Stars: ✭ 34 (+0%)
Mutual labels:  unix
Awesome Unix
All the UNIX and UNIX-Like: Linux, BSD, macOS, Illumos, 9front, and more.
Stars: ✭ 973 (+2761.76%)
Mutual labels:  unix
Unitial
🖥 My rc / configs / dotfiles 📂
Stars: ✭ 29 (-14.71%)
Mutual labels:  unix

========== errand-boy

.. image:: https://travis-ci.org/greyside/errand-boy.svg?branch=master :target: https://travis-ci.org/greyside/errand-boy .. image:: https://coveralls.io/repos/greyside/errand-boy/badge.png?branch=master :target: https://coveralls.io/r/greyside/errand-boy?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:

#. http://stackoverflow.com/a/13329386/241955 #. 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:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].