Skip to content

Commit 3f25b5d

Browse files
fix(robot-server): Don't hide exceptions in startup/shutdown handlers (#8080)
1 parent 1d046ea commit 3f25b5d

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

robot-server/Makefile

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,21 @@ ot_sources := $(ot_py_sources)
4545
clean_cmd = $(SHX) rm -rf build dist .coverage coverage.xml '*.egg-info' '**/__pycache__' '**/*.pyc' 'robot_server/**/.mypy_cache'
4646

4747
# Uvicorn command to run the robot server in dev mode.
48-
run_dev ?= uvicorn "robot_server:app" --host localhost --port 31950 --ws wsproto --reload
48+
#
49+
# "--lifespan on" ensures errors in startup and shutdown handlers won't be hidden.
50+
# See github.com/encode/starlette/issues/1138, fixed in Starlette v0.16.0?
51+
#
52+
# todo(mm, 2021-07-08): Figure out how to run the server with Python development
53+
# mode enabled, to expose more errors and warnings.
54+
# * Using a Makefile target-specific variable to set PYTHONDEVMODE=1
55+
# doesn't work because it applies the variable to the whole `pipenv run`
56+
# command, and we only want our inner server process running under dev mode,
57+
# not the outer pipenv process.
58+
# * Adding PYTHONDEVMODE=1 to the .env file specified by
59+
# OT_ROBOT_SERVER_DOT_ENV_PATH doesn't work because that's read too late.
60+
# * Doing `pipenv run env PYTHONDEVMODE=1 uvicorn ...` works, except it's
61+
# probably POSIX-only.
62+
run_dev ?= uvicorn "robot_server:app" --host localhost --port 31950 --ws wsproto --lifespan on --reload
4963

5064
.PHONY: all
5165
all: clean wheel

robot-server/opentrons-robot-server.service

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ After=opentrons-status-leds.service
66

77
[Service]
88
Type=notify
9-
ExecStart=uvicorn robot_server:app --uds /run/aiohttp.sock --ws wsproto
9+
# "--lifespan on" ensures errors in startup and shutdown handlers won't be hidden.
10+
# See github.com/encode/starlette/issues/1138, fixed in Starlette v0.16.0?
11+
ExecStart=uvicorn robot_server:app --uds /run/aiohttp.sock --ws wsproto --lifespan on
1012
# Stop the button blinking
1113
ExecStartPost=systemctl stop opentrons-gpio-setup.service
1214
Environment=OT_SMOOTHIE_ID=AMA RUNNING_ON_PI=true

0 commit comments

Comments
 (0)