Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pyAmak - noyau
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SMAC
AMAK
Python
PyAMAK
pyAmak - noyau
Commits
064f30fd
Commit
064f30fd
authored
4 years ago
by
Wissam Benadjaoud
Browse files
Options
Downloads
Patches
Plain Diff
Suite du nettoyage
parent
a0182a58
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pyAmakCore/classes/amas.py
+0
-4
0 additions, 4 deletions
pyAmakCore/classes/amas.py
pyAmakCore/classes/scheduler.py
+19
-58
19 additions, 58 deletions
pyAmakCore/classes/scheduler.py
with
19 additions
and
62 deletions
pyAmakCore/classes/amas.py
+
0
−
4
View file @
064f30fd
...
...
@@ -14,7 +14,6 @@ sys.path.insert(0, str(pathlib.Path(__file__).parent))
from
pyAmakCore.classes.environment
import
Environment
from
pyAmakCore.classes.scheduler
import
Scheduler
from
pyAmakCore.classes.schedulable
import
Schedulable
from
pyAmakCore.enumeration.scheduling
import
*
from
pyAmakCore.exception.override
import
ToOverrideWarning
from
pyAmakCore.enumeration.executionPolicy
import
*
...
...
@@ -24,8 +23,6 @@ class Amas(Schedulable):
Class Amas
"""
#TODO : corriger l'initialisation du scheduler
#TODO : scheduling_amas is not str.
def
__init__
(
self
,
environment
:
'
Environment
'
,
...
...
@@ -101,7 +98,6 @@ class Amas(Schedulable):
for
agent
in
agents
:
self
.
add_agent
(
agent
)
#TODO : tout les semaphores sont faux. Ils attendent un bool pas un int.
def
cycle
(
self
)
->
None
:
"""
Runs each agent of the list
...
...
This diff is collapsed.
Click to expand it.
pyAmakCore/classes/scheduler.py
+
19
−
58
View file @
064f30fd
...
...
@@ -5,6 +5,7 @@ import sys
import
pathlib
import
threading
import
time
from
typing
import
List
sys
.
path
.
insert
(
0
,
str
(
pathlib
.
Path
(
__file__
).
parent
))
...
...
@@ -16,55 +17,41 @@ class Scheduler:
Class Scheduler
"""
#TODO : est ce que un scheduler peut vraiment etre initialisé sans schedulables?
def
__init__
(
self
,
schedulables
=
[]):
def
__init__
(
self
,
schedulables
:
List
[
'
Schedulable
'
]):
self
.
_state
=
state
.
IDLE
self
.
_sleep
=
10
self
.
_locked
=
0
self
.
_onChange
=
[]
self
.
_defaultScheduler
=
None
self
.
_pendingAdditionSchedulables
=
[]
self
.
_pendingRemovalSchedulables
=
[]
self
.
_schedulables
=
schedulables
self
.
_stateLock
=
threading
.
Lock
()
def
get_pending_removal_schedulables
(
self
):
def
get_pending_removal_schedulables
(
self
)
->
List
[
'
Schedulable
'
]
:
"""
return _pendingRemovalSchedulables
"""
return
self
.
_pendingRemovalSchedulables
def
get_pending_addition_schedulables
(
self
):
def
get_pending_addition_schedulables
(
self
)
->
List
[
'
Schedulable
'
]
:
"""
return _pendingAdditionSchedulables
"""
return
self
.
_pendingAdditionSchedulables
def
get_on_change
(
self
):
"""
return on change value
"""
return
self
.
_onChange
def
get_state
(
self
):
def
get_state
(
self
)
->
'
state
'
:
"""
return current state of scheduler
"""
return
self
.
_state
def
get_locked
(
self
):
def
get_locked
(
self
)
->
int
:
"""
return locked
"""
return
self
.
_locked
def
get_on_stop
(
self
):
"""
return current on_stop value
"""
return
self
.
_onStop
def
get_default_scheduler
(
self
):
def
get_default_scheduler
(
self
)
->
'
Scheduler
'
:
"""
Create or return the default scheduler
"""
...
...
@@ -73,72 +60,51 @@ class Scheduler:
return
self
.
_defaultScheduler
def
get_sleep
(
self
):
def
get_sleep
(
self
)
->
int
:
"""
Getter for the sleep time
"""
return
self
.
_sleep
#TODO : type
#TODO : sleep shadow method
def
set_sleep
(
self
,
sleep
)
:
def
set_sleep
(
self
,
sleep
:
int
)
->
None
:
"""
Setter for the sleep time
"""
self
.
_sleep
=
10
/
sleep
#TODO : type
#TODO : Argument name should be lowercase
def
set_on_stop
(
self
,
onStop
):
"""
Set the method that must be executed when the system is stopped
"""
self
.
_onStop
=
onStop
#TODO : type
#TODO : Argument name should be lowercase
def
add_on_change
(
self
,
onChange
):
"""
Add a method that must be executed when the scheduler speed is changed
"""
self
.
_onChange
=
onChange
def
lock
(
self
):
def
lock
(
self
)
->
None
:
"""
Soft lock the scheduler to avoid a too early running
"""
self
.
_locked
+=
1
def
unlock
(
self
):
def
unlock
(
self
)
->
None
:
"""
Soft unlock the scheduler to avoid a too early running
"""
self
.
_locked
-=
1
#TODO : type
def
add
(
self
,
schedulable
):
def
add
(
self
,
schedulable
:
'
Schedulable
'
)
->
None
:
"""
Plan to add a schedulable
"""
self
.
_pendingAdditionSchedulables
.
append
(
schedulable
)
#TODO : type
def
remove
(
self
,
schedulable
):
def
remove
(
self
,
schedulable
:
'
Schedulable
'
)
->
None
:
"""
Plan to remove a schedulable
"""
self
.
_pendingRemovalSchedulables
.
append
(
schedulable
)
#TODO : type
def
is_running
(
self
):
def
is_running
(
self
)
->
bool
:
"""
Is the scheduler running ?
"""
return
self
.
_state
==
state
.
RUNNING
#TODO : type
#TODO : supprimer les partie inutile / finir la methode
def
start_with_sleep
(
self
,
time_sleep
)
:
def
start_with_sleep
(
self
,
time_sleep
:
int
)
->
None
:
"""
Set the delay between two cycles and launch the scheduler if it is not
running
...
...
@@ -146,7 +112,6 @@ class Scheduler:
if
self
.
_locked
>
0
:
return
self
.
set_sleep
(
time_sleep
)
# A vérifier si c'est juste ou "stateLock.lock();"
self
.
_stateLock
.
acquire
()
if
self
.
_state
==
state
.
IDLE
:
self
.
_state
=
state
.
RUNNING
...
...
@@ -168,7 +133,6 @@ class Scheduler:
if
self
.
_locked
>
0
:
return
self
.
set_sleep
(
0
)
# A vérifier si c'est juste ou "stateLock.lock();"
self
.
_stateLock
.
acquire
()
if
self
.
_state
==
state
.
IDLE
:
self
.
_state
=
state
.
PENDING_STOP
...
...
@@ -181,23 +145,20 @@ class Scheduler:
"""
Stop the scheduler if it is running
"""
# A vérifier si c'est juste ou "stateLock.lock();"
self
.
_stateLock
.
acquire
()
if
self
.
_state
==
state
.
RUNNING
:
self
.
_state
=
state
.
PENDING_STOP
self
.
_stateLock
.
release
()
#TODO : add() n'existe pas en python.
def
treat_pending_schedulables
(
self
):
#TODO : C'est quoi ce lien ??? il suffit pas de recopier java mot a mot ^^"
"""
Effectively Add or Remove the schedulables that were added or removed during
a cycle
to avoid {@link ConcurrentModificationException
a cycle
"""
while
self
.
_pendingAdditionSchedulables
!=
[]
:
while
self
.
_pendingAdditionSchedulables
:
self
.
_schedulables
.
append
(
self
.
_pendingAdditionSchedulables
[
0
])
del
self
.
_pendingAdditionSchedulables
[
0
]
while
self
.
_pendingRemovalSchedulables
!=
[]
:
while
self
.
_pendingRemovalSchedulables
:
self
.
_schedulables
.
append
(
self
.
_pendingRemovalSchedulables
[
0
])
del
self
.
_pendingRemovalSchedulables
[
0
]
...
...
@@ -209,7 +170,7 @@ class Scheduler:
for
schedulable
in
self
.
_schedulables
:
schedulable
.
on_scheduling_starts
()
must_stop
=
False
while
self
.
_state
==
state
.
RUNNING
and
must_stop
==
False
:
while
self
.
_state
==
state
.
RUNNING
and
not
must_stop
:
for
schedulable
in
self
.
_schedulables
:
schedulable
.
cycle
()
if
self
.
get_sleep
()
!=
0
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment