-
Notifications
You must be signed in to change notification settings - Fork 0
/
HPF.py
28 lines (21 loc) · 1023 Bytes
/
HPF.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from Scheduler import Scheduler, SchedulerState
from operator import attrgetter
class HPF(Scheduler):
def process_arrived(self, processes):
super(HPF, self).process_arrived(processes)
# run it if it is the first process
if len(self.processes) == len(processes) and self.state is None:
# it's as if the scheduler just finished saving last process data and
# looking to start executing a new one
self.state = SchedulerState.context_switching_dump
# notify it to act upon
self.notify()
def sort_processes(self):
self.processes.sort(key=attrgetter('process_number'), reverse=False)
self.processes.sort(key=attrgetter('priority'), reverse=True)
def stop_process(self):
self.running_process.stop(self.clock.time)
self.processes.remove(self.running_process)
def run(self):
super(HPF, self).run()
self.clock.notify_scheduler(self.clock.time + self.running_process.burst_time)