From db13d8acac479ecad7c3a23522360196694145b8 Mon Sep 17 00:00:00 2001 From: Etienne Pallier Date: Wed, 20 Mar 2019 22:18:36 +0100 Subject: [PATCH] updates: go_idle et affichage final fin process --- README.md | 2 +- pyros.py | 22 ++++++++++++++++++++-- src/agent/Agent.py | 9 +++++++-- src/agent/AgentA.py | 5 +++++ src/agent/AgentB.py | 10 ++++++++++ 5 files changed, 43 insertions(+), 5 deletions(-) mode change 100644 => 100755 src/agent/AgentA.py mode change 100644 => 100755 src/agent/AgentB.py diff --git a/README.md b/README.md index bbedb12..113ee52 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ Date: 19/03/2019 Author: E. Pallier -VERSION: 0.20.22 +VERSION: 0.20.23 Comment: pyros.py peut lancer plusieurs agents (A et B) en même temps (+ flush_commands + test) diff --git a/pyros.py b/pyros.py index cde8649..073c34a 100755 --- a/pyros.py +++ b/pyros.py @@ -382,7 +382,8 @@ def start(agent:str, configfile:str): cmd = f" Agent{agent_name[5:]}.py {configfile}" #if not test_mode(): execProcessFromVenv(cmd) - if not test_mode(): current_processes.append( (execProcessFromVenvAsync(cmd), agent_name) ) + #if not test_mode(): current_processes.append( (execProcessFromVenvAsync(cmd), agent_name, 0) ) + if not test_mode(): current_processes.append( [execProcessFromVenvAsync(cmd), agent_name, -1] ) # self._change_dir("..") os.chdir(current_dir) @@ -390,9 +391,12 @@ def start(agent:str, configfile:str): # self._change_dir('..') #os.chdir("..") # Wait for end of each process execution - for (p,agent) in current_processes: + #for (p,agent) in current_processes: + for process in current_processes: + p,agent,_ = process print(f"************ Waiting for end of execution of agent {agent} ************") p.wait() + process[2] = p.returncode print(f"************ END of execution of agent {agent} ************") if p.returncode == 0: printFullTerm(Colors.GREEN, f"Process {agent} executed successfully") @@ -401,8 +405,22 @@ def start(agent:str, configfile:str): printFullTerm(Colors.WARNING, f"Process {agent} execution failed") # self.addError(self.current_command, command) + print() + print() + print("Synthesis of the results:") + for process in current_processes: + p,agent,returncode = process + print(process) + if returncode == 0: + printFullTerm(Colors.GREEN, f"Process {agent} executed successfully") + # self.addExecuted(self.current_command, command) + else: + printFullTerm(Colors.WARNING, f"Process {agent} execution failed") + # self.addError(self.current_command, command) + #print("************ end of START() ************") # Only according to the last process status: + #return True if p.returncode==0 else False return True if p.returncode==0 else False diff --git a/src/agent/Agent.py b/src/agent/Agent.py index c918bca..ca7f9db 100755 --- a/src/agent/Agent.py +++ b/src/agent/Agent.py @@ -295,7 +295,8 @@ class Agent: self.SIMULATOR_COMMANDS = iter(self.SIMULATOR_COMMANDS_LIST) self.RUN_IN_THREAD = RUN_IN_THREAD self.set_status(self.STATUS_LAUNCH) - self.set_mode(self.MODE_IDLE) + self.set_idle() + #self.set_mode(self.MODE_IDLE) if not config_filename: config_filename = self.DEFAULT_CONFIG_FILE_NAME @@ -317,7 +318,8 @@ class Agent: self.set_mode_from_config(name) # TODO: remove - self.set_idle() + #self.set_idle() + self.set_active() # Create 1st survey if none #tmp = AgentSurvey.objects.filter(name=self.name) @@ -463,6 +465,9 @@ class Agent: at each iteration """ self.set_status(self.STATUS_ROUTINE_PROCESS) + if not self.is_active(): + self.print("I am IDLE, so I bypass the routine_process (do not send any new command)") + return if self.cmdts is None: self.cmdts = self.simulator_get_next_command_to_send() diff --git a/src/agent/AgentA.py b/src/agent/AgentA.py old mode 100644 new mode 100755 index 06f6a47..a3db42c --- a/src/agent/AgentA.py +++ b/src/agent/AgentA.py @@ -32,10 +32,15 @@ class AgentA(Agent): "go_active", + # Because of this command, the receiver agent + # will no more send any new command "go_idle", + # Not executed because receiver agent is now "idle" #"specific0", + # Because of this command, the receiver agent + # will now be able to send new commands "go_active", # Executed because receiver agent is now "active" diff --git a/src/agent/AgentB.py b/src/agent/AgentB.py old mode 100644 new mode 100755 index 5d531fd..4414b77 --- a/src/agent/AgentB.py +++ b/src/agent/AgentB.py @@ -27,8 +27,18 @@ class AgentB(Agent): SIMULATOR_COMMANDS_DEST = "AgentA" # Scenario to be executed SIMULATOR_COMMANDS_LIST = [ + "flush_commands", "go_active", + + # Because of this command, the receiver agent + # will no more send any new command + "go_idle", + "go_idle", "go_idle", + + # Because of this command, the receiver agent + # will now be able to send new commands + "go_active", ] """ "go_active", -- libgit2 0.21.2