本文整理汇总了Python中Simulation.start方法的典型用法代码示例。如果您正苦于以下问题:Python Simulation.start方法的具体用法?Python Simulation.start怎么用?Python Simulation.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Simulation
的用法示例。
在下文中一共展示了Simulation.start方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CommandsListener
# 需要导入模块: import Simulation [as 别名]
# 或者: from Simulation import start [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...')
示例2: Simulation_Control
# 需要导入模块: import Simulation [as 别名]
# 或者: from Simulation import start [as 别名]
class Simulation_Control(object):
""" Controls the simulation, either step by step, or in
a continuous mode.
"""
def __init__(self, SimulationStep):
self.OneStep = SimulationStep # function that launches one step of the simulation
## Status of the simulation programme
self.simulation = None # name of the simulation thread
self.busy = 0 # busy meter to avoid fatal parallelism between simulation and display
#self.previous_Disp_period = self.Disp_period = 1 # display period
def RunButtonClick(self, event=None):
self.simulation_steady_mode = True # Continuous functioning
self.Simulation_resume()
def PauseButtonClick(self,event=None):
self.Simulation_stop()
def Simulation_stop(self):
if self.simulation is not None:
self.simulation.stop()
if self.simulation.isAlive():
#print 'strange...'
#sleep(2)
self.simulation = None # well...
return False
self.simulation = None
return True
def Simulation_launch(self):
if self.busy > 0:
return False
# A new simulation thread is created
if self.Simulation_stop():
self.simulation = Simulation(self.OneStep)
self.simulation.start()
return True
def Simulation_resume(self):
return self.Simulation_launch()