Open tiagocoutinho opened 4 years ago
We have briefly discussed this issue on the last follow-up meeting, and later talking with @teresanunez the POV of DESY is:
on_stop, on_abort functions: this is also a feature which was asked for by our BL scientists. It would be a problem for us, if this disappears.
ok, we could keep on_stop
and on_abort
but change the implementation to something like:
class Macro:
def _run(self):
with macro_guard(self):
return self.run()
(disclaimer: I am making a suggestion before seeing the code)
My point is that the callbacks would be called inside the run procedure. This way it would be safe to make any macro API calls inside de callbacks.
When writing a macro class in sardana it is possible to define the methods
on_abort(self)
andon_stop(self)
to recover or handle error/stop cases respectively.While this seems useful at first glance, it has some limitations:
on_abort()
has not traceback information of what went wrongon_stop()
andon_abort()
. This includes for example a simple call toself.output()
The original motivation was that we (wrongly) assumed that asking the macro developer to write try/catch or context managers would be too complicated and we wanted to provide an easier interface. Turns out that, as usual, the solution provided by the language is a much better mechanism then a local invention based on wrong assumptions :-)
IMHO the python try/except and context manager mechanisms are easier and more powerful mechanisms and therefore better suited to handle these scenarios.
We could provide helpers and/or examples on most common cases: Here is an example of a context manager that ensures the motor comes back to the original position:
Therefore, I propose to:
on_abort()
andon_stop()
methods