def exec_(self):
"""**Internal method**. Execute macro as an iterator"""
self._macro_thread = threading.current_thread()
macro_status = self.getMacroStatus()
# make sure a 0.0 progress is sent
yield macro_status
# allow any macro to be paused at the beginning of its execution
self.pausePoint()
# Run the macro or obtain a generator
res = self.run(*self._in_pars)
# If macro returns a generator then running the macro means go through
# the generator steps, otherwise the macro has already ran
if isinstance(res, types.GeneratorType):
it = iter(res)
for i in it:
if operator.isMappingType(i):
new_range = i.get('range')
if new_range is not None:
macro_status['range'] = new_range
new_step = i.get('step')
if new_step is not None:
macro_status['step'] = new_step
elif operator.isNumberType(i):
macro_status['step'] = i
macro_status['state'] = 'step'
yield macro_status
# make sure a 'stop' progress is sent in case an exception occurs
macro_status['state'] = 'stop'
else:
self._out_pars = res
macro_status['step'] = 100.0
macro_status['state'] = 'finish'
yield macro_status
评论列表
文章目录