diff options
author | Erik Johnston <erik@matrix.org> | 2021-09-17 17:12:38 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2021-09-17 17:12:38 +0100 |
commit | c2d84edffc47f36fd2034e112efbab08d59d3e8b (patch) | |
tree | 85128c3d16bf79ad685b338250218b115d14770e | |
parent | Fix tests (diff) | |
download | synapse-c2d84edffc47f36fd2034e112efbab08d59d3e8b.tar.xz |
Don't create temporary function
-rw-r--r-- | synapse/http/server.py | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/synapse/http/server.py b/synapse/http/server.py index 07029e670c..ece71c78b2 100644 --- a/synapse/http/server.py +++ b/synapse/http/server.py @@ -669,7 +669,9 @@ def respond_with_json( if send_cors: set_cors_headers(request) - _write_json_to_request_in_thread(request, encoder, json_object) + run_in_background( + _async_write_json_to_request_in_thread, request, encoder, json_object + ) return NOT_DONE_YET @@ -810,7 +812,7 @@ def finish_request(request: Request): logger.info("Connection disconnected before response was written: %r", e) -def _write_json_to_request_in_thread( +async def _async_write_json_to_request_in_thread( request: SynapseRequest, json_encoder: Callable[[Any], str], json_object: Any, @@ -826,13 +828,10 @@ def _write_json_to_request_in_thread( expensive. """ - async def _inner_encode_in_thread(): - json_str = await defer_to_thread(request.reactor, json_encoder, json_object) - - try: - request.write(json_str) - request.finish() - except RuntimeError as e: - logger.info("Connection disconnected before response was written: %r", e) + json_str = await defer_to_thread(request.reactor, json_encoder, json_object) - run_in_background(_inner_encode_in_thread) + try: + request.write(json_str) + request.finish() + except RuntimeError as e: + logger.info("Connection disconnected before response was written: %r", e) |