Commit db13d8acac479ecad7c3a23522360196694145b8

Authored by Etienne Pallier
1 parent 5a76fb80
Exists in dev

updates: go_idle et affichage final fin process

@@ -71,7 +71,7 @@ Date: 19/03/2019 @@ -71,7 +71,7 @@ Date: 19/03/2019
71 71
72 Author: E. Pallier 72 Author: E. Pallier
73 73
74 -VERSION: 0.20.22 74 +VERSION: 0.20.23
75 75
76 Comment: 76 Comment:
77 pyros.py peut lancer plusieurs agents (A et B) en même temps (+ flush_commands + test) 77 pyros.py peut lancer plusieurs agents (A et B) en même temps (+ flush_commands + test)
@@ -382,7 +382,8 @@ def start(agent:str, configfile:str): @@ -382,7 +382,8 @@ def start(agent:str, configfile:str):
382 cmd = f" Agent{agent_name[5:]}.py {configfile}" 382 cmd = f" Agent{agent_name[5:]}.py {configfile}"
383 383
384 #if not test_mode(): execProcessFromVenv(cmd) 384 #if not test_mode(): execProcessFromVenv(cmd)
385 - if not test_mode(): current_processes.append( (execProcessFromVenvAsync(cmd), agent_name) ) 385 + #if not test_mode(): current_processes.append( (execProcessFromVenvAsync(cmd), agent_name, 0) )
  386 + if not test_mode(): current_processes.append( [execProcessFromVenvAsync(cmd), agent_name, -1] )
386 # self._change_dir("..") 387 # self._change_dir("..")
387 os.chdir(current_dir) 388 os.chdir(current_dir)
388 389
@@ -390,9 +391,12 @@ def start(agent:str, configfile:str): @@ -390,9 +391,12 @@ def start(agent:str, configfile:str):
390 # self._change_dir('..') 391 # self._change_dir('..')
391 #os.chdir("..") 392 #os.chdir("..")
392 # Wait for end of each process execution 393 # Wait for end of each process execution
393 - for (p,agent) in current_processes: 394 + #for (p,agent) in current_processes:
  395 + for process in current_processes:
  396 + p,agent,_ = process
394 print(f"************ Waiting for end of execution of agent {agent} ************") 397 print(f"************ Waiting for end of execution of agent {agent} ************")
395 p.wait() 398 p.wait()
  399 + process[2] = p.returncode
396 print(f"************ END of execution of agent {agent} ************") 400 print(f"************ END of execution of agent {agent} ************")
397 if p.returncode == 0: 401 if p.returncode == 0:
398 printFullTerm(Colors.GREEN, f"Process {agent} executed successfully") 402 printFullTerm(Colors.GREEN, f"Process {agent} executed successfully")
@@ -401,8 +405,22 @@ def start(agent:str, configfile:str): @@ -401,8 +405,22 @@ def start(agent:str, configfile:str):
401 printFullTerm(Colors.WARNING, f"Process {agent} execution failed") 405 printFullTerm(Colors.WARNING, f"Process {agent} execution failed")
402 # self.addError(self.current_command, command) 406 # self.addError(self.current_command, command)
403 407
  408 + print()
  409 + print()
  410 + print("Synthesis of the results:")
  411 + for process in current_processes:
  412 + p,agent,returncode = process
  413 + print(process)
  414 + if returncode == 0:
  415 + printFullTerm(Colors.GREEN, f"Process {agent} executed successfully")
  416 + # self.addExecuted(self.current_command, command)
  417 + else:
  418 + printFullTerm(Colors.WARNING, f"Process {agent} execution failed")
  419 + # self.addError(self.current_command, command)
  420 +
404 #print("************ end of START() ************") 421 #print("************ end of START() ************")
405 # Only according to the last process status: 422 # Only according to the last process status:
  423 + #return True if p.returncode==0 else False
406 return True if p.returncode==0 else False 424 return True if p.returncode==0 else False
407 425
408 426
src/agent/Agent.py
@@ -295,7 +295,8 @@ class Agent: @@ -295,7 +295,8 @@ class Agent:
295 self.SIMULATOR_COMMANDS = iter(self.SIMULATOR_COMMANDS_LIST) 295 self.SIMULATOR_COMMANDS = iter(self.SIMULATOR_COMMANDS_LIST)
296 self.RUN_IN_THREAD = RUN_IN_THREAD 296 self.RUN_IN_THREAD = RUN_IN_THREAD
297 self.set_status(self.STATUS_LAUNCH) 297 self.set_status(self.STATUS_LAUNCH)
298 - self.set_mode(self.MODE_IDLE) 298 + self.set_idle()
  299 + #self.set_mode(self.MODE_IDLE)
299 if not config_filename: 300 if not config_filename:
300 config_filename = self.DEFAULT_CONFIG_FILE_NAME 301 config_filename = self.DEFAULT_CONFIG_FILE_NAME
301 302
@@ -317,7 +318,8 @@ class Agent: @@ -317,7 +318,8 @@ class Agent:
317 318
318 self.set_mode_from_config(name) 319 self.set_mode_from_config(name)
319 # TODO: remove 320 # TODO: remove
320 - self.set_idle() 321 + #self.set_idle()
  322 + self.set_active()
321 323
322 # Create 1st survey if none 324 # Create 1st survey if none
323 #tmp = AgentSurvey.objects.filter(name=self.name) 325 #tmp = AgentSurvey.objects.filter(name=self.name)
@@ -463,6 +465,9 @@ class Agent: @@ -463,6 +465,9 @@ class Agent:
463 at each iteration 465 at each iteration
464 """ 466 """
465 self.set_status(self.STATUS_ROUTINE_PROCESS) 467 self.set_status(self.STATUS_ROUTINE_PROCESS)
  468 + if not self.is_active():
  469 + self.print("I am IDLE, so I bypass the routine_process (do not send any new command)")
  470 + return
466 471
467 if self.cmdts is None: 472 if self.cmdts is None:
468 self.cmdts = self.simulator_get_next_command_to_send() 473 self.cmdts = self.simulator_get_next_command_to_send()
src/agent/AgentA.py 100644 → 100755
@@ -32,10 +32,15 @@ class AgentA(Agent): @@ -32,10 +32,15 @@ class AgentA(Agent):
32 32
33 "go_active", 33 "go_active",
34 34
  35 + # Because of this command, the receiver agent
  36 + # will no more send any new command
35 "go_idle", 37 "go_idle",
  38 +
36 # Not executed because receiver agent is now "idle" 39 # Not executed because receiver agent is now "idle"
37 #"specific0", 40 #"specific0",
38 41
  42 + # Because of this command, the receiver agent
  43 + # will now be able to send new commands
39 "go_active", 44 "go_active",
40 45
41 # Executed because receiver agent is now "active" 46 # Executed because receiver agent is now "active"
src/agent/AgentB.py 100644 → 100755
@@ -27,8 +27,18 @@ class AgentB(Agent): @@ -27,8 +27,18 @@ class AgentB(Agent):
27 SIMULATOR_COMMANDS_DEST = "AgentA" 27 SIMULATOR_COMMANDS_DEST = "AgentA"
28 # Scenario to be executed 28 # Scenario to be executed
29 SIMULATOR_COMMANDS_LIST = [ 29 SIMULATOR_COMMANDS_LIST = [
  30 + "flush_commands",
30 "go_active", 31 "go_active",
  32 +
  33 + # Because of this command, the receiver agent
  34 + # will no more send any new command
  35 + "go_idle",
  36 + "go_idle",
31 "go_idle", 37 "go_idle",
  38 +
  39 + # Because of this command, the receiver agent
  40 + # will now be able to send new commands
  41 + "go_active",
32 ] 42 ]
33 """ 43 """
34 "go_active", 44 "go_active",