本文整理汇总了Python中interpreter.Interpreter.send方法的典型用法代码示例。如果您正苦于以下问题:Python Interpreter.send方法的具体用法?Python Interpreter.send怎么用?Python Interpreter.send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类interpreter.Interpreter
的用法示例。
在下文中一共展示了Interpreter.send方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: StateMachine
# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import send [as 别名]
#.........这里部分代码省略.........
# def setIOProcessors(self, dm):
# dm["_ioprocessors"] = {"scxml" : {"location" : dm["_x"]["self"]},
# "basichttp" : {"location" : dm["_x"]["self"]} }
def _open_document(self, uri):
if hasattr(uri, "read"):
return uri.read()
elif isinstance(uri, basestring) and re.search("<(.+:)?scxml", uri): #"<scxml" in uri:
self.filename = "<string source>"
self.filedir = None
return uri
else:
path, search_path = get_path(uri, self.filedir or "")
if path:
self.filedir, self.filename = os.path.split(os.path.abspath(path))
return open(path).read()
else:
msg = "No such file on the PYSCXMLPATH"
self.logger.error(msg + ": '%s'" % uri)
self.logger.error("PYTHONPATH: '%s'" % search_path)
raise IOError(errno.ENOENT, msg, uri)
def _start(self):
self.compiler.instantiate_datamodel()
self.interpreter.interpret(self.doc)
def _start_invoke(self, invokeid=None):
self.compiler.instantiate_datamodel()
self.interpreter.interpret(self.doc, invokeid)
def start(self):
'''Takes the statemachine to its initial state'''
if not self.interpreter.running:
raise RuntimeError("The StateMachine instance may only be started once.")
else:
doc = os.path.join(self.filedir, self.filename) if self.filedir else ""
self.logger.info("Starting %s" % doc)
self._start()
self.interpreter.mainEventLoop()
def start_threaded(self):
self._start()
eventlet.spawn(self.interpreter.mainEventLoop)
eventlet.greenthread.sleep()
def isFinished(self):
'''Returns True if the statemachine has reached it
top-level final state or was cancelled.'''
return self.is_finished
def cancel(self):
'''
Stops the execution of the StateMachine, causing
all the states in the current configuration to execute
their onexit blocks. The StateMachine instance now no longer
accepts events. For clarity, consider using the
top-level <final /> state in your document instead.
'''
self.interpreter.running = False
self.interpreter.externalQueue.put(Event("cancel.invoke.%s" % self.datamodel.get("_sessionid")))
def send(self, name, data={}):
'''
Send an event to the running machine.
@param name: the event name (string)
@param data: the data passed to the _event.data variable (any data type)
'''
self._send(name, data)
eventlet.greenthread.sleep()
def _send(self, name, data={}, invokeid = None, toQueue = None):
self.interpreter.send(name, data, invokeid, toQueue)
def In(self, statename):
'''
Checks if the state 'statename' is in the current configuration,
(i.e if the StateMachine instance is currently 'in' that state).
'''
return self.interpreter.In(statename)
def on_exit(self, sender, final):
if sender is self.interpreter:
self.is_finished = True
for timer in self.compiler.timer_mapping.values():
eventlet.greenthread.cancel(timer)
del timer
dispatcher.disconnect(self, "signal_exit", self.interpreter)
dispatcher.send("signal_exit", self, final=final)
def __enter__(self):
self.start_threaded()
return self
def __exit__(self, exc_type, exc_value, traceback):
if not self.isFinished():
self.cancel()