-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTask3.py
49 lines (42 loc) · 1.58 KB
/
Task3.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from threading import Thread
import time
class Task:
savedTime = None
startTime = None
endTime = None
runTime = 0
def __init__(self, taskTime, taskName):
self.taskTime = float(taskTime)
self.completed = False
self.taskName = taskName
self.savedTime = float(taskTime) * 10
def executeRR(self, runningTime):
if self.startTime is None:
self.startTime = time.time()
if self.taskTime > runningTime:
print("{} runs for {}'s".format(self.taskName, runningTime))
self.taskTime -= runningTime
st = time.time()
time.sleep(runningTime)
r = time.time() - st
self.runTime += r
string = ""
else:
print("{} runs for {}'s".format(self.taskName, self.taskTime))
# self.taskTime = 0
st = time.time()
time.sleep(self.taskTime)
self.endTime = time.time()
r = time.time() - st
self.runTime += r
self.completed = True
print("{} task competed".format(self.taskName))
def is_completed(self):
return self.completed
def get_proccess_info(self):
wait_time = self.endTime - (self.startTime + self.runTime)
print("{} wait time is '{}' ".format(self.taskName, wait_time), end="")
response_time = self.endTime - self.startTime
print("{} response time is '{}' ".format(self.taskName, response_time, end=""))
def __str__(self):
return "A task with {} seconds working thread".format(self.taskName)