Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
iotamak-core
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
IoTAMAK
iotamak-core
Commits
2befe983
Commit
2befe983
authored
3 years ago
by
shinedday
Browse files
Options
Downloads
Patches
Plain Diff
Improved scheduler wait with semaphore
parent
9cd7e771
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
dist/iotAmak-0.0.3-py3-none-any.whl
+0
-0
0 additions, 0 deletions
dist/iotAmak-0.0.3-py3-none-any.whl
iotAmak/scheduler.py
+14
-20
14 additions, 20 deletions
iotAmak/scheduler.py
with
14 additions
and
20 deletions
dist/iotAmak-0.0.3-py3-none-any.whl
+
0
−
0
View file @
2befe983
No preview for this file type
This diff is collapsed.
Click to expand it.
iotAmak/scheduler.py
+
14
−
20
View file @
2befe983
"""
"""
Scheduler class file
Scheduler class file
"""
"""
from
threading
import
Semaphore
from
time
import
sleep
from
time
import
sleep
import
sys
import
sys
...
@@ -19,9 +20,6 @@ class Scheduler(Schedulable):
...
@@ -19,9 +20,6 @@ class Scheduler(Schedulable):
def
__init__
(
self
,
broker_ip
:
str
)
->
None
:
def
__init__
(
self
,
broker_ip
:
str
)
->
None
:
Schedulable
.
__init__
(
self
,
broker_ip
,
"
Scheduler
"
)
Schedulable
.
__init__
(
self
,
broker_ip
,
"
Scheduler
"
)
self
.
sleep_between_cycle
=
0
self
.
ihm_token
=
0
self
.
paused
=
True
self
.
paused
=
True
self
.
nbr_agent
=
0
self
.
nbr_agent
=
0
...
@@ -32,8 +30,9 @@ class Scheduler(Schedulable):
...
@@ -32,8 +30,9 @@ class Scheduler(Schedulable):
self
.
subscribe
(
"
ihm/pause
"
,
self
.
pause
)
self
.
subscribe
(
"
ihm/pause
"
,
self
.
pause
)
self
.
subscribe
(
"
ihm/unpause
"
,
self
.
unpause
)
self
.
subscribe
(
"
ihm/unpause
"
,
self
.
unpause
)
self
.
agent_waiting
=
0
self
.
agent_semaphore
=
Semaphore
(
0
)
self
.
schedulable_waiting
=
0
self
.
schedulable_semaphore
=
Semaphore
(
0
)
self
.
ihm_semaphore
=
Semaphore
(
0
)
print
(
"
Init done
"
)
print
(
"
Init done
"
)
...
@@ -42,26 +41,26 @@ class Scheduler(Schedulable):
...
@@ -42,26 +41,26 @@ class Scheduler(Schedulable):
Function called when the IHM pause the scheduler
Function called when the IHM pause the scheduler
"""
"""
self
.
paused
=
True
self
.
paused
=
True
self
.
ihm_
token
=
0
self
.
ihm_
semaphore
.
acquire
()
def
unpause
(
self
,
client
,
userdata
,
message
)
->
None
:
def
unpause
(
self
,
client
,
userdata
,
message
)
->
None
:
"""
"""
Function called when the IHM unpause the scheduler
Function called when the IHM unpause the scheduler
"""
"""
self
.
paused
=
False
self
.
paused
=
False
self
.
ihm_
token
=
1
self
.
ihm_
semaphore
.
release
()
def
step
(
self
,
client
,
userdata
,
message
)
->
None
:
def
step
(
self
,
client
,
userdata
,
message
)
->
None
:
"""
"""
Function called by the IHM when the scheduler is in Step by Step mode
Function called by the IHM when the scheduler is in Step by Step mode
"""
"""
self
.
ihm_
token
+=
1
self
.
ihm_
semaphore
.
release
()
def
update_schedulable
(
self
,
client
,
userdata
,
message
)
->
None
:
def
update_schedulable
(
self
,
client
,
userdata
,
message
)
->
None
:
"""
"""
Function called whenever the amas/env have finished an action and is waiting
Function called whenever the amas/env have finished an action and is waiting
"""
"""
self
.
schedulable_
waiting
+=
1
self
.
schedulable_
semaphore
.
release
()
print
(
"
__Schedulable is waiting
"
)
print
(
"
__Schedulable is waiting
"
)
def
update_nbr_agent
(
self
,
client
,
userdata
,
message
)
->
None
:
def
update_nbr_agent
(
self
,
client
,
userdata
,
message
)
->
None
:
...
@@ -77,24 +76,22 @@ class Scheduler(Schedulable):
...
@@ -77,24 +76,22 @@ class Scheduler(Schedulable):
"""
"""
Called whenever an agent have done an action and is waiting
Called whenever an agent have done an action and is waiting
"""
"""
self
.
agent_
waiting
+=
1
self
.
agent_
semaphore
.
release
()
print
(
"
__Agent done
"
)
print
(
"
__Agent done
"
)
def
wait_agent
(
self
)
->
None
:
def
wait_agent
(
self
)
->
None
:
"""
"""
Called when the scheduler is waiting for all agent do have finished their action
Called when the scheduler is waiting for all agent do have finished their action
"""
"""
while
self
.
agent_waiting
<
self
.
nbr_agent
:
for
_
in
range
(
self
.
nbr_agent
):
sleep
(
self
.
wait_delay
)
self
.
agent_semaphore
.
acquire
()
self
.
agent_waiting
=
0
def
wait_schedulable
(
self
)
->
None
:
def
wait_schedulable
(
self
)
->
None
:
"""
"""
Called when the scheduler is waiting for both amas and env to have finished their action
Called when the scheduler is waiting for both amas and env to have finished their action
"""
"""
while
self
.
schedulable_waiting
<
2
:
for
_
in
range
(
2
):
sleep
(
self
.
wait_delay
)
self
.
schedulable_semaphore
.
acquire
()
self
.
schedulable_waiting
=
0
def
wait_ihm
(
self
)
->
None
:
def
wait_ihm
(
self
)
->
None
:
"""
"""
...
@@ -102,9 +99,7 @@ class Scheduler(Schedulable):
...
@@ -102,9 +99,7 @@ class Scheduler(Schedulable):
"""
"""
if
not
self
.
paused
:
if
not
self
.
paused
:
return
return
while
self
.
ihm_token
==
0
:
self
.
ihm_semaphore
.
acquire
()
sleep
(
self
.
wait_delay
)
self
.
ihm_token
-=
1
def
first_part
(
self
)
->
None
:
def
first_part
(
self
)
->
None
:
"""
"""
...
@@ -158,7 +153,6 @@ class Scheduler(Schedulable):
...
@@ -158,7 +153,6 @@ class Scheduler(Schedulable):
print
(
"
-Last part
"
)
print
(
"
-Last part
"
)
self
.
last_part
()
self
.
last_part
()
sleep
(
self
.
sleep_between_cycle
)
self
.
nbr_cycle
+=
1
self
.
nbr_cycle
+=
1
self
.
publish
(
"
scheduler/cycledone
"
,
""
)
self
.
publish
(
"
scheduler/cycledone
"
,
""
)
...
...
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