process Module

The process module wrap a process and IO redirection

class gaffer.process.Process(loop, pid, name, cmd, args=None, env=None, uid=None, gid=None, cwd=None, detach=False, shell=False, redirect_output=[], redirect_input=False, custom_streams=[], custom_channels=[], on_exit_cb=None)[source]

Bases: object

class wrapping a process

Args:

  • loop: main application loop (a pyuv Loop instance)
  • name: name of the process
  • cmd: program command, string)
  • args: the arguments for the command to run. Can be a list or a string. If args is a string, it’s splitted using shlex.split(). Defaults to None.
  • env: a mapping containing the environment variables the command will run with. Optional
  • uid: int or str, user id
  • gid: int or st, user group id,
  • cwd: working dir
  • detach: the process is launched but won’t be monitored and won’t exit when the manager is stopped.
  • shell: boolean, run the script in a shell. (UNIX only)
  • redirect_output: list of io to redict (max 2) this is a list of custom labels to use for the redirection. Ex: [“a”, “b”] will redirect stdoutt & stderr and stdout events will be labeled “a”
  • redirect_input: Boolean (False is the default). Set it if you want to be able to write to stdin.
  • custom_streams: list of additional streams that should be created and passed to process. This is a list of streams labels. They become available through streams attribute.
  • custom_channels: list of additional channels that should be passed to process.
active
close()[source]
closed
info

return the process info. If the process is monitored it return the last informations stored asynchronously by the watcher

kill(signum)[source]

send a signal to the process

monitor(listener=None)[source]

start to monitor the process

Listener can be any callable and receive (“stat”, process_info)

monitor_io(io_label, listener)[source]

subscribe to registered IO events

os_pid

return the process pid

spawn(once=False, graceful_timeout=None, env=None)[source]

spawn the process

stats
status

return the process status

stop()[source]

stop the process

unmonitor(listener)[source]

stop monitoring this process.

listener is the callback passed to the monitor function previously.

unmonitor_io(io_label, listener)[source]

unsubscribe to the IO event

write(data)[source]

send data to the process via stdin

writelines(data)[source]

send data to the process via stdin

class gaffer.process.ProcessConfig(name, cmd, **settings)[source]

Bases: object

object to maintain a process config

DEFAULT_PARAMS = {'gid': None, 'uid': None, 'env': {}, 'redirect_input': False, 'custom_channels': [], 'redirect_output': [], 'shell': False, 'args': [], 'custom_streams': [], 'cwd': None}
classmethod from_dict(config)[source]
get(key, default=None)[source]
make_process(loop, pid, label, env=None, on_exit=None)[source]

create a Process object from the configuration

Args:

  • loop: main pyuv loop instance that will maintain the process
  • pid: process id, generally given by the manager
  • label: the job label. Usually the process type. context. A context can be for example an application.
  • on_exit: callback called when the process exited.
to_dict()[source]
class gaffer.process.ProcessWatcher(loop, process)[source]

Bases: object

object to retrieve process stats

active
refresh(interval=0)[source]
stop(all_events=False)[source]
subscribe(listener)[source]
subscribe_once(listener)[source]
unsubscribe(listener)[source]
class gaffer.process.RedirectIO(loop, process, stdio=[])[source]

Bases: object

pipes_count = 2
start()[source]
stdio
stop(all_events=False)[source]
subscribe(label, listener)[source]
unsubscribe(label, listener)[source]
class gaffer.process.RedirectStdin(loop, process)[source]

Bases: object

redirect stdin allows multiple sender to write to same pipe

start()[source]
stop(all_events=False)[source]
write(data)[source]
writelines(data)[source]
class gaffer.process.Stream(loop, process, id)[source]

Bases: gaffer.process.RedirectStdin

create custom stdio

start()[source]
subscribe(listener)[source]
unsubscribe(listener)[source]
gaffer.process.get_process_stats(process=None, interval=0)[source]

Return information about a process. (can be an pid or a Process object)

If process is None, will return the information about the current process.