pyrolab.server.change_behavior#
- change_behavior(cls: Type[Instrument], instance_mode: str = 'session', instance_creator: Callable | None = None)[source]#
Dynamically add a behavior to a class.
Equivalent to using the
behaviordecorator on the class, but can be used dynamically during runtime. Services that specify some default behavior in the source code can be overridden using this function.Warning
This function modifies the behavior of the class in place! It does not returning a new class object.
- Parameters:
- clsclass
The class to be change the behavior of.
- instance_modestr
One of “session”, “single”, or “percall” (see manual for differences).
- instance_creatorcallable
A callable that creates a new instance of the class (see manual for more details).
- Raises:
- ValueError
If the
instance_modeis not one of “session”, “single”, or “percall”.- SyntaxError
If
instance_modeis not a string, or is missing.- TypeError
If the first argument is not a class, or
instance_creatoris not a callable.