manager Module

The manager module is a core component of gaffer. A Manager is responsible of maintaining processes and allows you to interract with them.


class gaffer.manager.Manager(loop=None)[source]

Bases: object

Manager - maintain process alive

A manager is responsible of maintaining process alive and manage actions on them:

  • increase/decrease the number of processes / process template
  • start/stop processes
  • add/remove process templates to manage

The design is pretty simple. The manager is running on the default event loop and listening on events. Events are sent when a process exit or from any method call. The control of a manager can be extended by adding apps on startup. For example gaffer provides an application allowing you to control processes via HTTP.

Running an application is done like this:

# initialize the application with the default loop
loop = pyuv.Loop.default_loop()
m = Manager(loop=loop)

# start the application

.... # do smth

m.stop() # stop the controlller # run the event loop


The loop can be omitted if the first thing you do is launching a manager. The run function is here for convenience. You can of course just run instead


The manager should be stopped the last one to prevent any lock in your application.

commit(name, graceful_timeout=0, env=None)[source]

Like ``scale(1) but the process won’t be kept alived at the end. It is also not handled uring scaling or reaping.


get a job config


get an OS process by ID. A process is a gaffer.Process instance attached to a process state that you can use.


generate a process id


get job’ infos

jobs_walk(callback, sessionid=None)[source]
kill(pid, sig)[source]

send a signal to a process

killall(name, sig)[source]

send a signal to all processes of a job

load(config, sessionid=None, env=None, start=True)[source]

load a process config object.


  • config: a process.ProcessConfig instance
  • sessionid: Some processes only make sense in certain contexts. this flag instructs gaffer to maintain this process in the sessionid context. A context can be for example an application. If no session is specified the config will be attached to the default session.
  • env: dict, None by default, if specified the config env variable will be updated with the env values.
monitor(listener, name)[source]

get stats changes on a process template or id

reload(name, sessionid=None)[source]

reload a process config. The number of processes is resetted to the one in settings and all current processes are killed


restart all processes in the manager. This function is threadsafe


Convenience function to use in place of If the manager is not started it raises a RuntimeError.

Note: if you want to use separately the default loop for this thread then just use the start function and run the loop somewhere else.

scale(name, n)[source]

Scale the number of processes in for a job. By using this function you can increase, decrease or set the number of processes in a template. Change is handled once the event loop is idling

n can be a positive or negative integer. It can also be a string containing the opetation to do. For example:

m.scale("sometemplate", 1) # increase of 1
m.scale("sometemplate", -1) # decrease of 1
m.scale("sometemplate", "+1") # increase of 1
m.scale("sometemplate", "-1") # decrease of 1
m.scale("sometemplate", "=1") # set the number of processess to 1
send(pid, lines, stream=None)[source]

send some data to the process


start the manager.


Start a job from which the config have been previously loaded


return job stats


stop the manager. This function is threadsafe


stop a jon. All processes of this job are stopped and won’t be restarted by the manager


stop a process


stop all processes of a job. Processes are just exiting and will be restarted by the manager.

unload(name_or_process, sessionid=None)[source]

unload a process config.

unmonitor(listener, name)[source]

get stats changes on a process template or id

unsubscribe(topic, channel)[source]
update(config, sessionid=None, env=None, start=False)[source]

update a process config. All processes are killed

walk(callback, name=None)[source]