schrodinger.utils.funcchains module¶
This module provides a system for collecting functions into ordered groups called chains. The functions in a chain can be executed sequentially, with an optional callback after each function that can be used to terminate the processing of the chain. An object may have multiple chains of functions, each identified by its respective decorator.
To use, create an object that inherits FuncChainMixin, and use a FuncChainDecorator to mark methods in that object as belonging to a particular chain. For example:
my_startup_functions = FuncChainDecorator()
class Foo(FuncChainMixin):
def __init__(self):
self.processFuncChain('startup')
@my_startup_functions(order=1)
def initVariables(self):
...
@my_startup_functions(order=2)
def setupWorkspace(self):
...
Supply a callback to self.processFuncChain(result_callback=bar) that accepts the return value of each function and returns True to continue processing the chain or False to terminate processing of the chain.
- class schrodinger.utils.funcchains.FuncChainMarker(label=None)¶
Bases:
schrodinger.utils.funcgroups.FuncGroupMarker
- customizeFuncResult(func, result)¶
Override this method to customize the return value of a function in the chain. This can be used to cast or interpret the return value or use the return value to build a custom object.
- Parameters
func – The function that produced the result
result – The return value of that function
- class schrodinger.utils.funcchains.FuncChainMixin(*args, **kwargs)¶
Bases:
schrodinger.utils.funcgroups.FuncGroupMixin
- __init__(*args, **kwargs)¶
- processFuncChain(chain=None, result_callback=None)¶
Execute each function in the specified chain sequentially in order.
The result_callback is called after each function with the return value of that function. This can be used to respond to the return value (e.g. present information to the user, get user feedback, log the result, etc.)
The return value of the result_callback determines whether processing will proceeed to the next function.
- Parameters
chain (FuncChainDecorator) – which chain to process
result_callback – the callback that will get called with the result of each function in the chain
- Returns
a list of the results from the functions