-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgressCheckThread.py
More file actions
53 lines (37 loc) · 1.63 KB
/
ProgressCheckThread.py
File metadata and controls
53 lines (37 loc) · 1.63 KB
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
50
51
52
53
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import threading
import time
class ProgressCheckThread(threading.Thread):
def __init__(self, PrintQueue, JobQueue):
#normal init
threading.Thread.__init__(self)
self.PrintQueue = PrintQueue
self.JobQueue = JobQueue
def run(self):
self.PrintQueue.put("ProgressThread: Starting..")
self._stop = threading.Event()
self.TotalJobs = self.JobQueue.qsize()
self.PrintQueue.put("ProgressThread: "+str(self.TotalJobs)+" Jobs loaded into JobQueue")
while True:
for x in range(0, 30):
if self.stopped():
break
time.sleep(1)
if not self.stopped():
#Get the current Queue Size
currsize = self.JobQueue.qsize()
#Divide the current size with our total to get % left
currval = float(currsize) / float(self.TotalJobs)
#Some rounding and multiplying to get us up to xxx number
currval = float(round(currval, 4) * 100)
#lets take our % left minus 100 to get percent done
percentdone = 100 - currval
self.PrintQueue.put("ProgressThread: Jobs Completed: "+str(percentdone)+"%")
if self.stopped():
self.PrintQueue.put("ProgressThread: Breaking..")
break
def stop(self):
self._stop.set()
def stopped(self):
return self._stop.isSet()