Skip to content

Commit

Permalink
fix(robot-server): Don't hide exceptions in startup/shutdown handlers (
Browse files Browse the repository at this point in the history
  • Loading branch information
SyntaxColoring authored Jul 22, 2021
1 parent 1d046ea commit 3f25b5d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 15 additions & 1 deletion robot-server/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,21 @@ ot_sources := $(ot_py_sources)
clean_cmd = $(SHX) rm -rf build dist .coverage coverage.xml '*.egg-info' '**/__pycache__' '**/*.pyc' 'robot_server/**/.mypy_cache'

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

.PHONY: all
all: clean wheel
Expand Down
4 changes: 3 additions & 1 deletion robot-server/opentrons-robot-server.service
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ After=opentrons-status-leds.service

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

0 comments on commit 3f25b5d

Please sign in to comment.