Public Access
added proper logging facility
This commit is contained in:
@@ -4,6 +4,7 @@ import time
|
||||
import sys
|
||||
import os
|
||||
import os.path
|
||||
import logging
|
||||
import tables
|
||||
import damaris.data.DataPool as DataPool
|
||||
import damaris.gui.ResultReader as ResultReader
|
||||
@@ -12,6 +13,8 @@ import damaris.gui.BackendDriver as BackendDriver
|
||||
import damaris.gui.ResultHandling as ResultHandling
|
||||
import damaris.gui.ExperimentHandling as ExperimentHandling
|
||||
|
||||
logger = logging.getLogger("damaris.script_interface")
|
||||
|
||||
def some_listener(event):
|
||||
if event.subject=="__recentexperiment" or event.subject=="__recentresult":
|
||||
r=event.origin.get("__recentresult",-1)+1
|
||||
@@ -20,7 +23,8 @@ def some_listener(event):
|
||||
ratio=100.0*r/e
|
||||
else:
|
||||
ratio=100.0
|
||||
print("\r%d/%d (%.0f%%)"%(r,e,ratio), end=' ')
|
||||
sys.stderr.write("\r%d/%d (%.0f%%)"%(r,e,ratio))
|
||||
sys.stderr.flush()
|
||||
|
||||
|
||||
class ScriptInterface:
|
||||
@@ -73,27 +77,29 @@ class ScriptInterface:
|
||||
if not self.exp_handling.is_alive():
|
||||
self.exp_handling.join()
|
||||
if self.exp_handling.raised_exception:
|
||||
print(": experiment script failed at line %d (function %s): %s"%(self.exp_handling.location[0],
|
||||
self.exp_handling.location[1],
|
||||
self.exp_handling.raised_exception))
|
||||
logger.error(": experiment script failed at line %d (function %s): %s",
|
||||
self.exp_handling.location[0],
|
||||
self.exp_handling.location[1],
|
||||
self.exp_handling.raised_exception)
|
||||
else:
|
||||
print(": experiment script finished")
|
||||
logger.info(": experiment script finished")
|
||||
self.exp_handling = None
|
||||
|
||||
if self.res_handling is not None:
|
||||
if not self.res_handling.is_alive():
|
||||
self.res_handling.join()
|
||||
if self.res_handling.raised_exception:
|
||||
print(": result script failed at line %d (function %s): %s"%(self.res_handling.location[0],
|
||||
self.res_handling.location[1],
|
||||
self.res_handling.raised_exception))
|
||||
logger.error(": result script failed at line %d (function %s): %s",
|
||||
self.res_handling.location[0],
|
||||
self.res_handling.location[1],
|
||||
self.res_handling.raised_exception)
|
||||
else:
|
||||
print(": result script finished")
|
||||
logger.info(": result script finished")
|
||||
self.res_handling = None
|
||||
|
||||
if self.back_driver is not None:
|
||||
if not self.back_driver.is_alive():
|
||||
print(": backend finished")
|
||||
logger.info(": backend finished")
|
||||
self.back_driver=None
|
||||
|
||||
except KeyboardInterrupt:
|
||||
@@ -120,14 +126,14 @@ class ScriptInterface:
|
||||
dump_file=None
|
||||
# todo
|
||||
except Exception as e:
|
||||
print("dump failed", e)
|
||||
logger.error("Dump failed: %s", e)
|
||||
|
||||
|
||||
|
||||
if __name__=="__main__":
|
||||
|
||||
if len(sys.argv)==1:
|
||||
print("%s: data_handling_script [spool directory]"%sys.argv[0])
|
||||
logger.error("%s: data_handling_script [spool directory]", sys.argv[0])
|
||||
sys.exit(1)
|
||||
if len(sys.argv)==3:
|
||||
spool_dir=os.getcwd()
|
||||
|
||||
Reference in New Issue
Block a user