From cd8a06a53bc0da129a2fba26a1b56b93d7fa85fb Mon Sep 17 00:00:00 2001 From: Ruben van de Ven Date: Wed, 6 Dec 2023 12:08:12 +0100 Subject: [PATCH] list which processes occupy port --- trap/socket_forwarder.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/trap/socket_forwarder.py b/trap/socket_forwarder.py index a5ab499..87445f0 100644 --- a/trap/socket_forwarder.py +++ b/trap/socket_forwarder.py @@ -1,8 +1,10 @@ from argparse import Namespace import asyncio +import errno import logging from multiprocessing import Event +import subprocess from typing import Set, Union, Dict, Any from typing_extensions import Self @@ -145,7 +147,14 @@ class WsRouter: # loop = tornado.ioloop.IOLoop.current() logger.info(f"Listen on {self.config.ws_port}") - self.application.listen(self.config.ws_port) + try: + self.application.listen(self.config.ws_port) + except OSError as e: + if e.errno == errno.EADDRINUSE: + logger.critical("Address already in use by process") + subprocess.run(["lsof", "-i", f"tcp:{self.config.ws_port:d}"]) + raise + loop = asyncio.get_event_loop() task = self.evt_loop.create_task(self.prediction_forwarder())