Skip to content
Snippets Groups Projects
Commit 5e586a1d authored by Florian Schröder's avatar Florian Schröder
Browse files

Update websocket close methods to be asynchronous

The close methods for websockets were updated to be asynchronous. This change was necessary to better handle the closing of active websockets both in the try/finally block and in the terminate method. The asyncio event loop was also employed to ensure all pending tasks are completed before closing.
parent 4c64e443
No related branches found
No related tags found
No related merge requests found
Pipeline #45233 passed
......@@ -52,7 +52,7 @@ class WebsocketExtension(Extension):
except Exception as e:
traceback.print_exception(e)
finally:
websocket.close()
await websocket.close()
async def send(self, ref: str, message: str):
if ref in self.active_websockets:
......@@ -60,8 +60,10 @@ class WebsocketExtension(Extension):
await websocket.send(message)
def terminate(self, *args, **kwargs):
loop_ = asyncio.get_event_loop()
for websocket in self.active_websockets.values():
websocket.close()
loop_.run_until_complete(websocket.close())
class WebsocketExtensionSetup(ExtensionSetup):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment