Commit 4e85387d authored by Lucas Bourneuf's avatar Lucas Bourneuf

expose yield_run for a coroutine behavior of the script running

parent c1267eb4
......@@ -78,7 +78,8 @@ build_pipeline.from_configfile = build_pipeline_from_configfile
build_pipeline.from_json = build_pipeline_from_json
def run(scripts:[Script], initial_context:str='', verbosity:int=0) -> str:
def yield_run(scripts:[Script], initial_context:str='', verbosity:int=0) -> (str, float):
"Yield context and duration found at each step of the running process"
if verbosity >= 1:
scripts = tuple(scripts)
print(f"RUNNING {len(scripts)} SCRIPTS…")
......@@ -105,10 +106,17 @@ def run(scripts:[Script], initial_context:str='', verbosity:int=0) -> str:
script_time = round(time.time() - script_start, 2)
if verbosity >= 1:
print(f"SCRIPT {idx}: {script.name} add {len(new_context.splitlines())} lines to the context in {script_time}s.")
yield context, script_time
run_time = round(time.time() - run_start, 2)
if verbosity >= 1:
print(f"RUN {len(context.splitlines())} lines built in {run_time}s.")
return context
def run(scripts:[Script], initial_context:str='', verbosity:int=0) -> str:
last = None
for out, _ in yield_run(scripts, initial_context, verbosity):
last = out
return last
def solve_context(context:str, *, nb_model:int=0) -> clyngor.Answers:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment