Commit 9c954944 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[experiments] Fix monitor command

The handling of the get call was not updated after the webapi module
refactor. This patch fixes this and also properly handles the case
the first call does not work and thus happens before the full ncurse
setup occures.

Fixes #66
parent 6237ba29
Pipeline #38181 passed with stage
in 8 minutes and 15 seconds
......@@ -61,6 +61,8 @@ from beat.core.hash import hashDataset
from . import common
from . import commands
from .webapi import WebAPIError
from .plotters import plot_impl as plotters_plot
from .plotters import pull_impl as plotters_pull
......@@ -983,22 +985,22 @@ class ExperimentMonitor(threading.Thread):
0 if first_run else self.interval.total_seconds()
):
status, answer = webapi.get(
"/api/v1/experiments/{}/?fields={}".format(self.name, fields)
)
if status != six.moves.http_client.OK:
try:
answer = webapi.get(
"/api/v1/experiments/{}/?fields={}".format(self.name, fields)
)
except WebAPIError as error:
logger.error(
"failed to get current state of {} on `{}', reason: {}".format(
self.name,
webapi.platform,
six.moves.http_client.responses[status],
error,
)
)
self.stop_event.set()
self.queue.put({"error": status})
self.queue.put({"error": error})
else:
data = simplejson.loads(answer)
self.queue.put(data)
self.queue.put(answer)
if first_run:
first_run = False
......@@ -1137,16 +1139,17 @@ def monitor(ctx, name):
if not killed:
line += 1
pad.timeout(-1)
pad.addstr(
line,
0,
textwrap.shorten("Experiment done, press any key to leave", width=width),
curses.A_BOLD,
)
pad.move(line, 0)
pad.refresh(pad_height - height, 0, 0, 0, height - 1, width - 1)
pad.getkey()
if pad:
pad.timeout(-1)
pad.addstr(
line,
0,
textwrap.shorten("Experiment done, press any key to leave", width=width),
curses.A_BOLD,
)
pad.move(line, 0)
pad.refresh(pad_height - height, 0, 0, 0, height - 1, width - 1)
pad.getkey()
curses.echo()
curses.nocbreak()
......
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