本文整理汇总了Python中Simulation.stop方法的典型用法代码示例。如果您正苦于以下问题:Python Simulation.stop方法的具体用法?Python Simulation.stop怎么用?Python Simulation.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Simulation
的用法示例。
在下文中一共展示了Simulation.stop方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CommandsListener
# 需要导入模块: import Simulation [as 别名]
# 或者: from Simulation import stop [as 别名]
class CommandsListener(threading.Thread):
def __init__(self, thymioController, mainLogger):
threading.Thread.__init__(self)
# Create socket for listening to simulation commands
self.__sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.__sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.__sock.bind((cl.COMMANDS_LISTENER_HOST, cl.COMMANDS_LISTENER_PORT))
self.__sock.listen(5)
self.__thymioController = thymioController
self.__mainLogger = mainLogger
self.__simulation = None
self.__counter = pr.starter_number
def run(self):
while 1:
try:
# Waiting for client...
self.__mainLogger.debug("CommandListener - Waiting on accept...")
conn, (addr, port) = self.__sock.accept()
self.__mainLogger.debug('CommandListener - Received command from (' + addr + ', ' + str(port) + ')')
if addr not in cl.TRUSTED_CLIENTS:
self.__mainLogger.error(
'CommandListener - Received connection request from untrusted client (' + addr + ', ' + str(
port) + ')')
continue
# Receive one message
self.__mainLogger.debug('CommandListener - Receiving command...')
recvOptions = recvOneMessage(conn)
self.__mainLogger.debug('CommandListener - Received ' + str(recvOptions))
if recvOptions.kill:
# Received killing command -> Stop everything
self.__thymioController.killRequest()
if self.__simulation:
self.__simulation.stop()
break
elif recvOptions.start and (not self.__simulation or self.__simulation.isStopped()):
# Adding experiment number to pr.EXPERIMENT_NAME
experiment_name = pr.EXPERIMENT_NAME + "_" + str(self.__counter)
self.__counter += 1
# Received start request AND simulation is not running -> Start a new simulation
self.__mainLogger.debug("CommandListener - Starting simulation...")
self.__simulation = Simulation(self.__thymioController, recvOptions.debug, experiment_name)
self.__thymioController.setSimulation(self.__simulation)
self.__simulation.start()
elif recvOptions.stop and self.__simulation and not self.__simulation.isStopped(): # TODO: Stop properly
# Received stop request AND simulation is up and running -> Stop the simulation
self.__mainLogger.debug("CommandListener - Stopping simulation...")
self.__simulation.stop()
self.__simulation = None
elif recvOptions.stopthymio:
self.__mainLogger.debug("CommandListener - Stopping Thymio...")
self.__thymioController.stopThymio()
except:
self.__mainLogger.critical(
'Error in CommandsListener: ' + str(sys.exc_info()[0]) + ' - ' + traceback.format_exc())
self.__mainLogger.debug('CommandListener - KILLED -> Exiting...')