Public Access
no the print in the experiment and result script are also printed
This commit is contained in:
1 parent
1bb92a9157
commit
9b9a0ec1df
4 files changed
+59
-9
No files matched your search
@@ -7,7 +7,7 @@ import traceback
|
||||
import logging
|
||||
import ast
|
||||
from damaris.data import Resultable
|
||||
from damaris.gui.ExperimentHandling import StopExperiment
|
||||
from damaris.gui.ExperimentHandling import StopExperiment, _SandboxStdout
|
||||
|
||||
logger = logging.getLogger("damaris.result_handling")
|
||||
|
||||
@@ -16,16 +16,24 @@ class ResultHandling(threading.Thread):
|
||||
runs the result script in sandbox
|
||||
"""
|
||||
|
||||
def __init__(self, script_data, result_iterator, data_pool):
|
||||
def __init__(self, script_data, result_iterator, data_pool, log_callback=None):
|
||||
threading.Thread.__init__(self,name="result handler")
|
||||
self.script=script_data
|
||||
self.results=result_iterator
|
||||
self.data_space=data_pool
|
||||
self.quit_flag=self.results.quit_flag
|
||||
self._log_callback = log_callback
|
||||
if self.data_space is not None:
|
||||
self.data_space["__recentresult"]=-1
|
||||
|
||||
def run(self):
|
||||
# Redirect stdout/stderr so print() in sandboxed scripts goes to the GUI
|
||||
_orig_stdout = sys.stdout
|
||||
_orig_stderr = sys.stderr
|
||||
if self._log_callback is not None:
|
||||
sys.stdout = _SandboxStdout(self._log_callback)
|
||||
sys.stderr = _SandboxStdout(self._log_callback)
|
||||
|
||||
# execute it
|
||||
dataspace={}
|
||||
data_classes = __import__('damaris.data', dataspace, dataspace, ['*'])
|
||||
@@ -88,6 +96,10 @@ class ResultHandling(threading.Thread):
|
||||
traceback_file=None
|
||||
dataspace=None
|
||||
|
||||
# Restore stdout/stderr
|
||||
sys.stdout = _orig_stdout
|
||||
sys.stderr = _orig_stderr
|
||||
|
||||
def sleep(self, seconds):
|
||||
self.quit_flag.wait(seconds)
|
||||
if self.quit_flag.isSet():
|
||||
|
||||
Reference in new issue
Block a user