class littleworkers.Pool(workers=1, debug=False, wait_time=0.1)

The main pool object. Manages a set of specified workers.


commands = [
    'ls -al',
    'cd /tmp && mkdir foo',
    'echo "Hello There."',
    'sleep 2 && echo "Done."'
lil = Pool(workers=2)

Optionally accepts a workers kwarg. Default is 1.

Optionally accepts a debug kwarg. Default is False.

Optionally accepts a wait_time kwarg. Default is 0.1.


Adds a process to the pool.


A hook to control how often the busy-wait loop runs.

By default, sleeps for 0.1 seconds.


Returns the number of commands to be run.

Useful as a hook if you use a different structure for the commands.


Given a provided command (string or list), creates a new process to execute the command.


A hook for inspecting the pool’s current status.

By default, simply makes a log message and returns the length of the pool.


Fetches the next command for processing.

Will return None if there are no commands remaining (unless Pool.debug = True).


A hook to override how the commands are added.

By default, simply copies the provided command list to the internal commands list.


A hook to alter the kwargs given to subprocess.Process.

Takes a command argument, which is unused by default, but can be used to switch the flags used.

By default, only specifies shell=True.


Removes a process to the pool.

Fails silently if the process id is no longer present (unless Pool.debug = True).

run(commands=None, callback=None)

The method to actually execute all the commands with the pool.

Optionally accepts a commands kwarg, as a shortcut not to have to call Pool.prepare_commands.


Sets up a callback to be run whenever a process finishes.

If called with None or without any args, it will clear any existing callback.