PyFunc
- class savant.base.pyfunc.PyFunc(module, class_name, kwargs=None, dev_mode=False)
PyFunc structure that defines instantiation parameters for an object implementing
BasePyFuncImpl
.To instantiate the specified module and class after configuration was finished, call
load_user_code()
.The instance will be available through
instance
property.A pyfunc can be configured to be run in dev mode. Pyfuncs in dev mode are reloaded at runtime before each call (each frame) if the source file has changed since the last one. Additionally, pyfuncs in dev mode gracefully recover from error in code, allowing the pipeline to stay up and continue processing.
Note
This class is meant to be defined in a module config, not instantiated directly.
Note
Check pipeline element hierarchy to see which pipeline elements use PyFunc structure.
For example, define a
PyFuncElement
- element: pyfunc module: module.pyfunc_implementation_module class_name: PyFuncImplementationClass
where
PyFuncImplementationClass
inherits fromBasePyFuncPlugin
or fromNvDsPyFuncPlugin
for Deepstream pipeline.- load_user_code()
Load (or reload) the user module/class specified in the PyFunc fields. It’s necessary to call this at least once before starting the pipeline.
- property instance: BasePyFuncImpl
Returns resolved PyFunc implementation.
- __call__(*args, **kwargs)
Calls resolved PyFunc implementation if its a subclass of
BasePyFuncCallableImpl
, otherwise no-op.
- check_reload()
Checks if reload is needed and reloads in case it is.