Skip to content

Commit f1dc80d

Browse files
committed
Switch to sansio websockets back-end
Uvicorn uses the now deprecated `websockets.legacy` back end by default. It also supports the newer `sansio` interface. As far as I can tell, either works, so I'm not sure why legacy is the default: backwards compatibility I guess. I'd like to switch to the newer implementation now, before we are using websockets in anger, as it feels wrong to start out with deprecation warnings in the test suite!
1 parent 90c0a60 commit f1dc80d

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

src/labthings_fastapi/server/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def serve_from_cli(
161161
server = ThingServer.from_config(config, True if args.debug else False)
162162
if dry_run:
163163
return server
164-
uvicorn.run(server.app, host=args.host, port=args.port)
164+
uvicorn.run(server.app, host=args.host, port=args.port, ws="websockets-sansio")
165165
except BaseException as e:
166166
if args.fallback:
167167
print(f"Error: {e}")
@@ -174,7 +174,7 @@ def serve_from_cli(
174174
)
175175
)
176176

177-
uvicorn.run(app, host=args.host, port=args.port)
177+
uvicorn.run(app, host=args.host, port=args.port, ws="websockets-sansio")
178178
else:
179179
if isinstance(e, (ValidationError, ThingImportFailure)):
180180
print(f"Error reading LabThings configuration:\n{e}")

tests/test_fallback.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def test_actual_server_fallback():
170170

171171
# Starting the server is a SystemExit
172172
with pytest.raises(SystemExit, match="3") as excinfo:
173-
uvicorn.run(server.app, port=5000)
173+
uvicorn.run(server.app, port=5000, ws="websockets-sansio")
174174
server_error = excinfo.value
175175
assert server.startup_failure is not None
176176
assert server.startup_failure["thing"] == "bad_thing"

tests/test_mjpeg_stream.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,4 @@ def test_mjpeg_stream(client):
7878
assert isinstance(telly, Telly)
7979
telly.framerate = 6
8080
telly.frame_limit = -1
81-
uvicorn.run(server.app, port=5000)
81+
uvicorn.run(server.app, port=5000, ws="websockets-sansio")

0 commit comments

Comments
 (0)