def _step(self):
"""
Moves one step forward in the event loop.
This will collect the next task from the deque, and run it.
This is an internal function and should not be called.
"""
if not self._running:
raise RuntimeError("Loop is not running.")
if not self.running_tasks:
# TODO: Handle loop wind-down.
return
next_task = self.running_tasks.popleft()
assert isinstance(next_task, _VSContext)
if next_task.state is VSCtxState.SUSPENDED:
# It hasn't reached a wake-up call yet, so re-add it to the end of the deque.
self.running_tasks.append(next_task)
return
if next_task.state == VSCtxState.RUNNING:
# No need to use safe_raise here.
# This will never raise a VS-handled exception, because it's a native invoke function.
raise RuntimeError("Current task state is RUNNING - this should never happen!")
if next_task.state is VSCtxState.PENDING:
# It's newly created, or otherwise ready. Continue execution.
# This should automatically pop or push it as appropriate.
try:
return self._start_execution(next_task)
except NotImplementedError as e:
print("Fatal error in Vanstein:")
print("Instruction '{}' is not implemented yet.".format(
self.bytecode_engine.current_instruction.opname))
print("Function disassembly:")
dis.dis(next_task)
print("Current context: {}".format(self.bytecode_engine.current_context))
print("Current instruction: {}".format(self.bytecode_engine.current_instruction))
raise
except BaseException as e:
print("Fatal error in Vanstein:")
traceback.print_exc(file=sys.stdout)
print("Function disassembly:")
dis.dis(next_task)
print("Current context: {}".format(self.bytecode_engine.current_context))
print("Current instruction: {}".format(self.bytecode_engine.current_instruction))
raise
if next_task.state is VSCtxState.FINISHED:
# Hopefully, we never have to see this.
warnings.warn("Reached FINISHED task in event loop...")
return next_task
评论列表
文章目录