-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkerqueue.py
More file actions
executable file
·57 lines (52 loc) · 1.75 KB
/
workerqueue.py
File metadata and controls
executable file
·57 lines (52 loc) · 1.75 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
54
55
56
57
#!/bin/env python3
from multiprocessing import Process
import queue #as queue
from subprocess import Popen, PIPE
class VeresQueue(queue):
'''
Placeholder for all information from a command, stdout, stderr, rc values
'''
#def __init__(self, command):
def __init__(self):
#__init__(self) #, command)
self.command = command
self.stdout = ""
self.stderr = ""
self.rc = ""
class Worker(Process):
'''
Placeholder for all information from a command, stdout, stderr, rc values
'''
def __init__(self, queue, live_run = False):
__init__(self)
self.queue = queue
self.live_run = live_run
self.stdout = ""
self.stderr = ""
self.rc = ""
def run(self):
while not self.queue.empty():
# grab work; do something to it (+1); then put the result on the output queue
work = self.queue.get()
if self.live_run == True:
print("Live Run", end = ' ' )
self.do_work(work)
else:
print("Dry Run", end = ' ' )
print("{} got {}".format(self.name, work))
self.queue.task_done()
else:
print("queue {} done.".format(self.queue))
def do_work(self, command):
'''
Only one worker will do, because the queues are processed sequentially
'''
print('do_work: ', command)
try:
process = Popen(command, shell=True, stdout=PIPE, stderr=PIPE)
stdout, stderr = process.communicate()
print("Popen stdout: ", stdout)
print("Popen stderr: ", stderr)
except Exception:
print("Popen ging fout")
#Hier moet nog een log actie bij