process Module
The process module wrap a process and IO redirection
-
class gaffer.process.Process(loop, id, name, cmd, group=None, 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[source]
-
close()[source]
-
closed[source]
-
info[source]
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
-
pid[source]
return the process pid
-
spawn()[source]
spawn the process
-
status[source]
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.ProcessWatcher(loop, pid)[source]
Bases: object
object to retrieve process stats
-
active[source]
-
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[source]
-
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_info(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.