-
Notifications
You must be signed in to change notification settings - Fork 0
/
jobstreamreader.py
executable file
·70 lines (57 loc) · 1.83 KB
/
jobstreamreader.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#standard libs
from threading import Thread
from subprocess import Popen, PIPE
import sys
import logging
import site
site.addsitedir("../libs")
#own libs
import config
from dhash import DistributedHash
log = logging.getLogger("verifyta_statusreader")
if config.debug():
log.setLevel(logging.DEBUG)
else:
log.setLevel(logging.INFO)
class JobStreamReader:
def __init__(self, stream, uid):
self._stream = stream
self._uid = uid
self._loadtable = DistributedHash("uppaal_load")
self._throughputtable = DistributedHash("uppaal_throughput")
self._finalresult = ""
def startreading(self):
log.info("Started reading output from verifyta with id: {}"
.format(self._uid))
while True:
word = self._next_word()
if(word is None):
return self._finalresult
if word == "Load:":
log.info("read Load")
self._loadtable[self._uid] = self._next_word()
sys.stdout.flush()
if word == "Throughput:":
self._throughputtable[self._uid] = self._next_word()
sys.stdout.flush()
def _next_word(self):
word = ""
out = self._readchar()
if(out == ""):
return None
while out == " ":
out = self._readchar()
while out != " " and out != "":
word += out
out = self._readchar()
return word
def _readchar(self):
out = self._stream.read(1)
self._finalresult += out
return out
if __name__ == "__main__":
p = Popen([config.verifytapath, "../xmlfiles/train-gate.xml"],
stdout=PIPE, stderr=PIPE)
reader = JobStreamReader(p.stdout, "asdasd")
output = reader.startreading()
log.info("output was {}".format(output))