Hooks¶
Built-in¶
- libpermian.hooks.builtin.pipeline_ended(pipeline)¶
Signal the pipeline and all non-daemon threads have ended and no further action should be done by the pipeline itself.
The only thing pipeline will be doing after this hook is waiting for all possible non-daemon thread callbacks for this hook to be finished.
Register¶
- libpermian.hooks.register.define(func)¶
Define hook function.
This should be used purely as function decorator where the defined function should have no body, as it will be replaced by a function which will call all callables assigned to this hook.
Example of use:
@hooks.define def process_started(pid, some_other_value=None): pass
- Parameters:
func (function) – Function which will be transformed to hook
- Returns:
Hook function which when called calls all associated callbacks
- libpermian.hooks.register.run_on(hook_func)¶
Assign callback function to given hook_func. This decorator compares the hook function signature with the callback function signature and if they are not compatible raises IncompatibleCallback exception.
Important note: The callback has to have the same function signature as the hook including the default values, otherwise, the callback function will be considered as incompatible. This requirement is caused by limitation of passing default values in current implementation.
The decorated callback has to be a function, partial function or object of callable class with compatible __call__ signature. Current implementation doesn’t handle lambda functions or classmethods.
- Parameters:
hook_func (function) – Hook function for which the callback should be called
- Returns:
function decorator used for callback registration
- libpermian.hooks.register.run_threaded_on(hook_func)¶
Similar as run_on, but the callback is started as (non-daemon) thread.
For more details see run_on.
- Parameters:
hook_func (function) – Hook function for which the callback should be called
- Returns:
function decorator used for callback registration