Skip to content

Commit cbdc6fb

Browse files
committed
- don't redirect to index in run and upload interfaces (now unused)
- pass pipe FD to usercode process so early logs/errors are caught.
1 parent 65f3190 commit cbdc6fb

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

runner/start.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,16 @@ def __init__(self):
6767
os.chown(self.USER_CODE_PATH, 1000, 1000) # pi:pi
6868

6969
self.HOPPER_CLIENT = HopperClient()
70+
71+
self.LOG_PIPE_NAME = PipeName((PipeType.INPUT, "log", "starter"), self.PIPE_DIRECTORY)
72+
self.HOPPER_CLIENT.open_pipe(self.LOG_PIPE_NAME, delete=True, create=True)
7073

7174
self.USER_PIPE_NAME = PipeName((PipeType.INPUT, "start-button", "starter"), self.PIPE_DIRECTORY)
7275
self.HOPPER_CLIENT.open_pipe(self.USER_PIPE_NAME, delete=True, create=True)
7376

7477
self.FLASK_PIPE_NAME = PipeName((PipeType.OUTPUT, "starter", "starter"), self.PIPE_DIRECTORY)
7578
self.HOPPER_CLIENT.open_pipe(self.FLASK_PIPE_NAME, delete=True, create=True, blocking=True)
7679

77-
self.LOG_PIPE_NAME = PipeName((PipeType.INPUT, "log", "starter"), self.PIPE_DIRECTORY)
78-
self.HOPPER_CLIENT.open_pipe(self.LOG_PIPE_NAME, delete=True, create=True)
79-
8080
self.__load_start_graphic()
8181
self.__init_gpio()
8282

@@ -105,6 +105,8 @@ def __start_usercode(self):
105105
# Send the erase escape sequence to clear remote logs
106106
self.HOPPER_CLIENT.write(self.LOG_PIPE_NAME, self.ERASE_ESCAPE_SEQUENCE)
107107

108+
pipe_fd = self.HOPPER_CLIENT.get_pipe_by_pipe_name(self.LOG_PIPE_NAME).fd
109+
108110
environment = dict(os.environ)
109111
environment["PYTHONPATH"] = ROBOT_LIB_LOCATION
110112
# Start the user code.
@@ -113,7 +115,8 @@ def __start_usercode(self):
113115
# python -u /path/to/the_code.py
114116
sys.executable, "-u", self.USER_CODE_ENTRYPOINT_PATH,
115117
],
116-
stderr=subprocess.STDOUT,
118+
stdout=pipe_fd,
119+
stderr=pipe_fd,
117120
bufsize=1, # Line-buffered
118121
close_fds="posix" in sys.builtin_module_names, # Only if we're not on Windows
119122
env=environment,

shepherd/blueprints/run/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def get_output():
4747
@blueprint.route("/toggle_auto_refresh", methods=["POST"])
4848
def toggle_auto_refresh():
4949
session["auto_refresh"] = not session.get("auto_refresh", True)
50-
return redirect(url_for(".index"))
50+
return "", 204
5151

5252
@blueprint.route("/picture")
5353
def get_picture():
@@ -61,10 +61,10 @@ def start():
6161
"mode": mode.value,
6262
"zone": int(zone)
6363
})
64-
return redirect(url_for(".index"))
64+
return "", 204
6565

6666

6767
@blueprint.route("/stop", methods=["POST"])
6868
def stop():
6969
send("stop")
70-
return redirect(url_for(".index"))
70+
return "", 204

shepherd/blueprints/upload/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def upload():
3636
else:
3737
flash("Your file looks good!", "success") # TODO: run a linter on the code?
3838
run.send("upload")
39-
return redirect(url_for(".index"))
39+
return "", 204
4040

4141
def chown_usercode():
4242
for root, dirs, files in os.walk(current_app.config["SHEPHERD_USER_CODE_PATH"]):

0 commit comments

Comments
 (0)