Author: tmckay
Date: 2012-05-15 19:42:02 +0000 (Tue, 15 May 2012)
New Revision: 5377
Modified:
trunk/cumin/bin/cumin-data
trunk/cumin/bin/cumin-report
trunk/cumin/bin/cumin-web
trunk/parsley/python/parsley/loggingex.py
Log:
Tweaks after testing.
* Make the PipeThread class daemonized.
* Also, provide a stop() with an immediate return for PipeThread so it can be called
reliably from the main thread. Move pipethread.stop() out of the shutdown routine (so
stderr and stdout are the very last things to be stopped).
BZ800065
Modified: trunk/cumin/bin/cumin-data
===================================================================
--- trunk/cumin/bin/cumin-data 2012-05-15 18:29:45 UTC (rev 5376)
+++ trunk/cumin/bin/cumin-data 2012-05-15 19:42:02 UTC (rev 5377)
@@ -274,8 +274,6 @@
def shutdown():
if mint:
mint.stop()
- if pipeThread:
- pipeThread.stop()
log.info("about to call logging shutdown")
logging.shutdown()
@@ -290,6 +288,8 @@
except:
tm = 5
t.join(tm)
+ if pipeThread:
+ pipeThread.stop(immediate=True)
return adjust_return(passed_init, return_code)
def make_ctrl_c(sig, frame):
Modified: trunk/cumin/bin/cumin-report
===================================================================
--- trunk/cumin/bin/cumin-report 2012-05-15 18:29:45 UTC (rev 5376)
+++ trunk/cumin/bin/cumin-report 2012-05-15 19:42:02 UTC (rev 5377)
@@ -251,8 +251,6 @@
def shutdown():
if mint:
mint.stop()
- if pipeThread:
- pipeThread.stop()
log.info("about to call logging shutdown")
logging.shutdown()
@@ -267,7 +265,8 @@
except:
tm = 5
t.join(tm)
-
+ if pipeThread:
+ pipeThread.stop(immediate=True)
return adjust_return(passed_init, return_code)
def make_ctrl_c(sig, frame):
Modified: trunk/cumin/bin/cumin-web
===================================================================
--- trunk/cumin/bin/cumin-web 2012-05-15 18:29:45 UTC (rev 5376)
+++ trunk/cumin/bin/cumin-web 2012-05-15 19:42:02 UTC (rev 5377)
@@ -283,8 +283,6 @@
def shutdown():
if cumin:
cumin.stop()
- if pipeThread:
- pipeThread.stop()
log.info("about to call logging shutdown")
logging.shutdown()
@@ -299,6 +297,8 @@
except:
tm = 5
t.join(tm)
+ if pipeThread:
+ pipeThread.stop(immediate=True)
return adjust_return(passed_init, return_code)
def make_ctrl_c(sig, frame):
Modified: trunk/parsley/python/parsley/loggingex.py
===================================================================
--- trunk/parsley/python/parsley/loggingex.py 2012-05-15 18:29:45 UTC (rev 5376)
+++ trunk/parsley/python/parsley/loggingex.py 2012-05-15 19:42:02 UTC (rev 5377)
@@ -163,7 +163,8 @@
that the thread has exited unexpectedly, potentially allowing them to clean up
the IO being handled by this thread.
"""
- def __init__(self, descriptors, paths, call_on_fail=None, rollover_size =
1024*1024):
+ def __init__(self, descriptors, paths, call_on_fail=None,
+ rollover_size = 1024*1024):
assert len(descriptors) == len(paths)
assert type(descriptors) in (list,tuple)
@@ -175,7 +176,8 @@
super(PipeLogThread, self).__init__()
self.name = self.__class__.__name__
-
+ self.immediate = False
+ self.daemon = True
self.rollover_size = rollover_size
self.call_on_fail = call_on_fail
@@ -208,10 +210,15 @@
try:
while not stop:
r, w, e = select.select(self.descriptors+[self.stop_r], [], [])
+
+ # If we have been told to stop immediately, do so.
+ if self.stop_r in r:
+ if self.immediate:
+ break
+ stop = True
+
for desc in r:
- if desc == self.stop_r:
- stop = True
- else:
+ if desc != self.stop_r:
msg = os.read(desc,1024)
if msg != "":
if self.rollover_size != 0:
@@ -227,9 +234,13 @@
for key, value in self.files.items():
value[0].close()
- def stop(self):
+ def stop(self, immediate=False):
if self.isAlive():
+ self.immediate = immediate
os.write(self.stop_w,"\n")
+ if immediate:
+ return
+
# This gives the thread a chance to write out
# anything pending on an input pipe.
for i in range(5):