Skip to content
Snippets Groups Projects
Commit 9cd7e771 authored by shinedday's avatar shinedday
Browse files

Greatly improved wait

parent dce535f8
No related branches found
No related tags found
No related merge requests found
......@@ -175,3 +175,74 @@ Pour ajouter des attributs a l'initialisation aux agents il suffit de rajouter d
**A AJOUTER**
un .config dans les experience avec la version du coeur
# diagrame de classe
```mermaid
classDiagram
class Amas{
int next_id
List~Cmd~ agent_cmd
List~Dict~ agents_metrics
on_initialization()
on_initial_agents_creation()
add_agent()
push_agent()
agent_log()
agent_metric()
on_cycle_begin()
on_cycle_end()
run()
}
class Agent{
List~Dict~ neighbors
List~Dict~ next_neighbors
on_initialization()
on_cycle_begin()
on_cycle_end()
add_neighbor()
log(message)
publish()
on_perceive()
on_decide()
on_act()
send_metric() Dict
run()
}
class Env{
on_initialization()
on_cycle_begin()
on_cycle_end()
run()
}
class Scheduler
class MqttClient{
~Paho mqtt client~ client
subscribe(topic, fun)
publish(topic, message)
}
class Schedulable{
int exit_bool
int nbr_cycle
int wait_delay
int wake_up_token
wake_up()
wait()
exit_procedure()
}
class SSHClient
MqttClient <|-- Schedulable
Schedulable <|-- Scheduler
Schedulable <|-- Agent
Schedulable <|-- Env
Schedulable <|-- Amas
SSHClient <|-- Amas
```
\ No newline at end of file
File added
......@@ -5,6 +5,7 @@ from time import sleep
import sys
import pathlib
import threading
sys.path.insert(0, str(pathlib.Path(__file__).parent.parent))
......@@ -23,14 +24,14 @@ class Schedulable(MqttClient):
self.subscribe("ihm/exit", self.exit_procedure)
self.nbr_cycle: int = 0
self.wait_delay: float = 0.01
self.wake_up_token: int = 0
self.semaphore = threading.Semaphore(0)
def wake_up(self, client, userdata, message) -> None:
"""
Called by the scheduler to wake up the schedulable
"""
self.wake_up_token += 1
self.semaphore.release()
# print("Waked up")
def wait(self) -> None:
......@@ -38,9 +39,7 @@ class Schedulable(MqttClient):
Basic wait method
"""
# print("Waiting")
while self.wake_up_token == 0:
sleep(self.wait_delay)
self.wake_up_token -= 1
self.semaphore.release()
# print("End wait")
def exit_procedure(self, client, userdata, message) -> None:
......
......@@ -3,7 +3,7 @@ from setuptools import setup, find_packages
setup(
name='iotAmak',
packages=find_packages(),
version='0.0.2',
version='0.0.3',
description='AmakFramework in python',
author='SMAC - GOYON Sebastien',
install_requires=[],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment