Process invocation and management interfaces.
sys
os0
signal0
functools0
contextlib0
typing0
types0
builtins0
kernel0
runtime0
thread0
files0
__control_lock__0
__control_lock__ = thread.amutex()
__interject_lock__0
__interject_lock__ = thread.amutex()
controlled0
controlled = __control_lock__.locked
current_process_id0
current_process_id = os.getpid()
parent_process_id0
parent_process_id = os.getppid()
main_thread_id0
main_thread_id = thread.identify()
index0
index = {
'root': ('thread', thread.identify(), None),
}
__fork_lock__0
__fork_lock__ = thread.amutex()
fork_prepare_callset0
fork_prepare_callset = set()
fork_parent_callset0
fork_parent_callset = set()
fork_child_callset0
fork_child_callset = set()
fork_child_cleanup0
fork_child_cleanup = set()
getattr0
getattr=getattr
signal_codes166%
Mapping of categorized signal names to signal (integer) codes.
signal_codes = {
'process/suspend': signal.SIGTSTP,
'process/resume': signal.SIGCONT,
'process/stop': signal.SIGSTOP,
'process/continue': signal.SIGCONT,
'process/terminate' : signal.SIGTERM,
'process/quit' : signal.SIGQUIT,
'process/interrupt' : signal.SIGINT,
'process/kill' : signal.SIGKILL,
'limit/cpu': signal.SIGXCPU,
'limit/file': signal.SIGXFSZ,
'limit/time': signal.SIGVTALRM,
'terminal/stop': signal.SIGTSTP,
'terminal/query': getattr(signal, 'SIGINFO', None) or getattr(signal, 'SIGUSR1', None),
'terminal/delta': getattr(signal, 'SIGWINCH', None),
'terminal/closed': signal.SIGHUP,
'terminal/background-read': signal.SIGTTIN,
'terminal/background-write': signal.SIGTTOU,
'user/1': signal.SIGUSR1,
'user/2': signal.SIGUSR2,
'exception/floating-point': signal.SIGFPE,
'exception/broken-pipe': signal.SIGPIPE,
'error/invalid-memory-access': signal.SIGBUS,
'error/restricted-memory-access': signal.SIGSEGV,
'error/invalid-instruction': signal.SIGILL,
'error/invalid-system-call': signal.SIGSYS,
}
signals0
signals = signal_codes
signal_names0
Mapping of signal (integer) codes to categorized names.
signal_names = dict([(v, k) for k, v in signal_codes.items()])
fatal_signals0
Set of signals that would cause an immediate exit if SIG_DFL were set.
fatal_signals = {
signal.SIGINT,
signal.SIGTERM,
getattr(signal, 'SIGXCPU', None),
getattr(signal, 'SIGXFSZ', None),
getattr(signal, 'SIGVTALRM', None),
getattr(signal, 'SIGPROF', None),
getattr(signal, 'SIGUSR1', None),
getattr(signal, 'SIGUSR2', None),
}
signal_identifiers0
Mapping of signal codes to identifiers used in POSIX header files.
signal_identifiers = {
getattr(signal, name): name
for name in dir(signal)
if name.startswith('SIG') and name[3] != '_' and isinstance(getattr(signal, name), int)
}
interject0
interject(main_thread_exec)
Trip the main thread by sending the process a SIGUSR2 signal in order to cause any running system call to exit early. Used in conjunction with fault.system.runtime.interject
clear_atexit_callbacks50%
clear_atexit_callbacks()
In cases where there may be process dependent callbacks, add this to the fork_child_callset to clear the callbacks.
_after_fork_parent340%
_after_fork_parent(child_pid)
_after_fork_child1135%
_after_fork_child()
Exit0
Extension of SystemExit for use with interjections.
Exitunspecified_status_code
unspecified_status_code = 255
Exitusage_query_code
usage_query_code = 200
Exitraised0
raised(self)
Invocation0
A structure representing the invocation of a system process and the specification of the means of exiting. Normally, used to describe how the process was invoked and the corresponding parameters, argv and environ, in which the invocation should be reacting to.
For system invocation, the parameters dictionary will have two entries by default: 'system' and 'type'.
Invocationcontext
The Invocation that caused the creation of this Invocation. By default and when created from system, this property is None.
context = None
Invocationparameters
Arbitrary storage for the parameteres of the invocation. Usually, 'type', 'system', and 'structured' keys are present.
parameters = None
Invocation__init__0
__init__(self, exit_method)
Invocationexit0
exit(self, result)
Perform the exit method designated during the initialization of the invocation.
Invocationfs_pwd0
The working directory of the process when the Invocation was created.
Invocationargv0
Arguments provided by the system without the leading command name.
Invocationargs0
args = argv
@property
Invocationenviron0dict
The environment variables collected from the system during the creation of the instance.
Invocationimports271%
imports(self, envvars)
Copy the given envvars from os.environ into the invocation's parameters. The snapshot of imported environment variables may be accessed using environ.
InvocationimportsParameters
Invocationsystem664%
system(Class, context, environ)
Create an instance representing that of the invocation from the operating system. Primarily, information is retrieved from the sys and os module.
InvocationsystemParameters
contextA reference context identifying the Invocation caused this invocation to be created.
Invocationsystem_exit_method0
system_exit_method(Class, exit_status)
A means of exit used with a Fork.trap managed process.
Injecting the exception on the main thread, this can also be used within regular Python processes.
ControlException0
Process control exceptions for significant events.
This is a control exception inheriting from BaseException. It should not be directly trapped, but subclasses may use it to classify exceptions that are not necessarily indicative of a failure.
ControlException__kill__
__kill__ = None
ControlExceptionraised0
raised(self)
Critical0
An exception used to communicate that a fatal condition was identified.
Critical__kill__
__kill__ = True
panic0
panic()
Raise a Critical exception in the main thread forcing the process to exit.
Interruption0
Similar to KeyboardInterrupt, but causes control to exit with the signal, and calls critical status hooks.
Primarily used to cause signal exit codes that are usually masked with KeyboardInterrupt.
Interruption__kill__
__kill__ = True
Interruption__init__20%
__init__(self, type)
Interruption__str__70%
__str__(self)
Interruptionraised40%
raised(self)
Register a system-level atexit handler that will cause the process to exit with the configured signal.
Interruptioninterrupt30%
interrupt(Class, signo, frame)
Signal handler that interjects an Interruption instance into the main thread.
Default signal handler for SIGINT.
Interruptionvoid0
void(signo, frame)
Python-level signal handler that does nothing.
Interruptionfilter0
filter(Class, *sigs)
Assign the void signal handler to the all of the given signal numbers.
Interruptioncatch0
catch(Class, *sigs)
Assign the interrupt signal handler to the all of the given signal numbers.
Interruptiontrap0
trap(Class)
Signal handler for a root process.
Fork0
Exception used to signal Fork.trap to replace the existing managed call.
Usual case is that a Fork.trap call is made on the main thread where other threads are created to run the actual program. Given that the program is finished and another should be ran as if the current program were never ran, the ControlException can be raised in the main thread replacing the initial callable given to Fork.trap.
The exception should only be used through the provided classmethods.
This exception should never be displayed in a traceback as it is intended to be caught by Fork.trap.
Fork__controlled_thread_id__
__controlled_thread_id__ = None
Fork__init__0
__init__(self, controller, *args, **kw)
Fork__str__10%
__str__(self)
Forkpivot40%
pivot(self, T)
Forksubstitute0
substitute(Class, callable, *args, **kw)
Substitute the existing control call with the given one.
Immediately raises a Fork instance in the calling thread to be caught by a corresponding trap call.
Only to be used in cases where it is known that the current frame stack is being managed by trap.
Forkdispatch657%int
dispatch(Class, controller, *args, **kw)
Execute the given callable with the given arguments in a child process. This performs an interject call. Given that pivot was called to execute the program, the pivot function will catch the exception, in the child, and execute the replacement.
ForkdispatchParameters
ForkdispatchReturns
- int
The child process' PID.
ForkdispatchExceptions
- Critical
Raised when the returns in the branches did not return.
Forktrap190%
trap(Class, controller, *args, **kw)
Establish a point for substituting the process. Trap provides an exception trap for replacing the controlling stack. This is used to perform safe fork operations that allow tear-down of process specific resources in a well defined manner.
| NOTE | |
Due to the varying global process state that may exist in a given process, it is often better to start a new Python instance. |
critical190%
critical(context, callable, *args, **kw)
A callable used to trap exceptions and interject a Critical instance caused by the original. This function is intended for critical sections where the failure is likely to cause the application to become unresponsive via usual routes.
critical may return, but must never raise.
For example:
from fault.system.process import critical
def fun():
while True:
# critical loop
# any exception causes the process to terminate
...
critical(None, fun)
protect100%
protect(*init)
Perpetually protect the main thread using a sleep loop that can only exit using an interjection.
Used by control to hold the main thread in Fork.trap for applications that rely on a set of threads to perform the actual work.
protectExceptions
- Critical
Raised in cases where the infinite loop exits.
control1056%
control(main, *args, **kw)
A program that calls this is making an explicit declaration that signals should be defaulted and the main thread should be protected from uninterruptable calls to allow prompt process exits while still performing critical state restoration.
The given main is executed with the given positionals args and keywords kw inside of a Fork.trap call. Fork handles formal exits and main-call substitution.
timeout60%
timeout()
SIGALRM based context manager for maximum time interruptions.
concurrently388%
concurrently(controller)
Dispatch the given controller in a child process of a control controlled process. The returned object is a reference to the result that will block until the child process has written the serialized response to a pipe.
Used to create very simple fork trees or workers that need to send completion reports back to the parent. This expects the calling process to have been launched with control.
concurrentlyParameters
fs_pwd0files.Path
fs_pwd()
Construct a fault.system.files.Path instance referring to PWD or the current working directory if the environment variable is not defined or it is an empty string.
The returned path is not maintained within any cache so repeat calls will create a new instance.
fs_chdir0files.Path
fs_chdir(directory)
Update PWD and the current working directory.
The current working directory is set prior to the environment being updated. Exceptions should not require PWD to be reset by the caller.
fs_chdirReturns
The given directory for chaining if it is a fault.system.files.Path instance. Otherwise, the result of fs_pwd is returned.
_scheduler_loop0
_scheduler_loop(ks, proxy, limit, final)
Scheduling0kernel.Scheduler
Scheduling()
Initialize or return process.scheduler.
Accessing process.scheduler will perform this automatically.
__getattr__166%
__getattr__(name)