MCPcopy Index your code
hub / github.com/LabPy/lantz / call

Method call

lantz/action.py:99–134  ·  view source on GitHub ↗
(self, instance, *args, **kwargs)

Source from the content-addressed store, hash-verified

97 return self.__name__
98
99 def call(self, instance, *args, **kwargs):
100 name = self.__name__
101
102 # This part calls to the underlying function wrapping
103 # and timing, logging and error handling
104 with instance._lock:
105 if args or kwargs:
106 instance.log_info('Calling {} with ({}, {}))', name, args, kwargs)
107 else:
108 instance.log_info('Calling {}', name)
109
110 try:
111 values = inspect.getcallargs(self.func, *(instance, ) + args, **kwargs)
112 fargs = self.args
113 values = tuple(values[farg] for farg in fargs)[1:]
114 if len(values) == 1:
115 t_values = (self.pre_action(values[0], instance), )
116 else:
117 t_values = self.pre_action(values, instance)
118 except Exception as e:
119 instance.log_error('While pre-processing ({}, {}) for {}: {}', args, kwargs, name, e)
120 raise e
121
122 if args or kwargs:
123 instance.log_debug('(raw) Calling {} with {}', name, t_values)
124
125 try:
126 tic = time.time()
127 out = self.func(instance, *t_values)
128 instance.timing.add(name, time.time() - tic)
129 instance.log_info('{} returned {}', name, out)
130
131 return out
132 except Exception as e:
133 instance.log_error('While calling {} with {}. {}', name, t_values, e)
134 raise e
135
136 def pre_action(self, value, instance=None):
137 procs = _dget(self.action_processors, instance)

Callers

nothing calls this directly

Calls 6

pre_actionMethod · 0.95
log_infoMethod · 0.80
log_errorMethod · 0.80
log_debugMethod · 0.80
timeMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected