summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcpp/demo/IceStorm/replicated/expect.py10
-rw-r--r--demoscript/Util.py21
-rwxr-xr-xscripts/Expect.py3
3 files changed, 24 insertions, 10 deletions
diff --git a/cpp/demo/IceStorm/replicated/expect.py b/cpp/demo/IceStorm/replicated/expect.py
index a4f747223de..f6da746197a 100755
--- a/cpp/demo/IceStorm/replicated/expect.py
+++ b/cpp/demo/IceStorm/replicated/expect.py
@@ -43,6 +43,14 @@ Util.cleanDbDir("db/node")
Util.cleanDbDir("db/registry")
print("ok")
+sys.stdout.write("cleaning old log files... ")
+for f in ["db/DemoIceStorm-1.out", "db/DemoIceStorm-2.out", "db/DemoIceStorm-3.out"]:
+ try:
+ os.remove(f)
+ except:
+ pass
+print("ok")
+
if Util.defaultHost:
args = ' --IceGrid.Node.PropertiesOverride="Ice.Default.Host=127.0.0.1"'
else:
@@ -92,6 +100,7 @@ time.sleep(3)
sub.expect('[0-9][0-9]/[0-9][0-9].*\n[0-9][0-9]/[0-9][0-9]')
print("ok")
+sys.stdout.write("shutting down... ")
sub.kill(signal.SIGINT)
sub.waitTestSuccess()
pub.kill(signal.SIGINT)
@@ -116,3 +125,4 @@ admin.sendline('registry shutdown Master')
admin.sendline('exit')
admin.waitTestSuccess()
node.waitTestSuccess()
+print("ok")
diff --git a/demoscript/Util.py b/demoscript/Util.py
index efe9e2a467d..33d34f91d4d 100644
--- a/demoscript/Util.py
+++ b/demoscript/Util.py
@@ -90,15 +90,19 @@ class filereader(Expect.reader):
Expect.reader.__init__(self, desc, p, None)
def run(self):
-
+ self.keepReading = True
try:
- while True:
+ while True and self.keepReading == True:
c = self.p.read(1)
if not c:
time.sleep(0.1)
+ # Refresh position so we don't get stuck at EOF
+ # while the file is still being written
+ # (Does not happen in all Python versions)
+ self.p.seek(self.p.tell())
continue
- if c == '\r': continue
+ if c == '\r':continue
self.cv.acquire()
try:
# Depending on Python version and platform, the value c could be a
@@ -110,11 +114,15 @@ class filereader(Expect.reader):
self.cv.notify()
finally:
self.cv.release()
+ self.p.close()
except ValueError as e:
pass
except IOError as e:
print(e)
+ def stopReading(self):
+ self.keepReading = False;
+
class FileExpect(object):
def __init__(self, path):
@@ -124,7 +132,7 @@ class FileExpect(object):
self.matchindex = 0 # the index of the matched pattern
self.match = None # The last match
- self.f = open(path)
+ self.f = open(path, 'r')
self.r = filereader(path, self.f)
# The thread is marked as a daemon thread. This is done so that if
@@ -169,10 +177,7 @@ class FileExpect(object):
return self.matchindex
def terminate(self):
- try:
- self.f.close()
- except:
- pass
+ self.r.stopReading()
self.r.join()
self.r = None
diff --git a/scripts/Expect.py b/scripts/Expect.py
index 9b579aba63d..cb25a45cd70 100755
--- a/scripts/Expect.py
+++ b/scripts/Expect.py
@@ -163,8 +163,7 @@ class reader(threading.Thread):
return buf
def match(self, pattern, timeout, matchall = False):
- """pattern is a list of string, regexp duples.
- """
+ # pattern is a list of string, regexp duples.
if timeout is not None:
end = time.time() + timeout