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

Having issue with dumping semaphore

parent e5347167
No related branches found
No related tags found
No related merge requests found
...@@ -4,25 +4,18 @@ from pyAmakCore.classes.agent import Agent ...@@ -4,25 +4,18 @@ from pyAmakCore.classes.agent import Agent
class SimpleAgent(Agent): class SimpleAgent(Agent):
""" pass
test
"""
class SimpleAmas(Amas): class SimpleAmas(Amas):
"""
test
"""
def on_initial_agents_creation(self) -> None: def on_initial_agents_creation(self) -> None:
for i in range(10): for i in range(10):
self.add_agent(Agent(self)) self.add_agent(SimpleAgent(self))
class SimpleEnv(Environment): class SimpleEnv(Environment):
""" pass
test
"""
env = SimpleEnv() env = SimpleEnv()
...@@ -31,8 +24,3 @@ amas = SimpleAmas(env) ...@@ -31,8 +24,3 @@ amas = SimpleAmas(env)
amas.put_token() amas.put_token()
amas.start() amas.start()
"""
There are no visible memory leak in pyAmakCore
"""
\ No newline at end of file
File added
import pickle
from time import sleep
from pyAmakCore.classes.amas import Amas
from pyAmakCore.classes.environment import Environment
from pyAmakCore.classes.agent import Agent
class SimpleAgent(Agent):
def __init__(self, amas):
self.i = 0
super().__init__(amas)
def on_cycle_begin(self) -> None:
self.i += 1
class SimpleAmas(Amas):
def on_initial_agents_creation(self) -> None:
for i in range(10):
self.add_agent(SimpleAgent(self))
def on_cycle_begin(self) -> None:
if self.get_cycle() == 0:
self.save()
def save(self):
with open('filename.pickle', 'wb') as handle:
pickle.dump(self.get_agents()[0].get_id(), handle, protocol=pickle.HIGHEST_PROTOCOL)
sleep(500)
@classmethod
def load(cls, amas_object):
with open('filename.pickle', 'wb') as handle:
amas_object = pickle.load(handle)
class SimpleEnv(Environment):
pass
env = SimpleEnv()
amas = SimpleAmas(env)
amas.put_token()
amas.start()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment