Skip to content

Commit 1522f7e

Browse files
committed
mimic dash error if running app on port already in use
1 parent f25cc4e commit 1522f7e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

plotly_resampler/figure_resampler/figure_resampler.py

+11
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
__author__ = "Jonas Van Der Donckt, Jeroen Van Der Donckt, Emiel Deprost"
1212

13+
import sys
14+
import socket
1315
import warnings
1416
from typing import Tuple
1517

@@ -160,6 +162,15 @@ def show_dash(
160162
self._host = kwargs.get("host", "127.0.0.1")
161163
self._port = kwargs.get("port", "8050")
162164

165+
# check if self._port is already in use
166+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
167+
if s.connect_ex(('localhost', int(self._port))) == 0:
168+
error_message = "Address already in use\n" \
169+
f"Port {self._port} is in use by another program. " \
170+
"Either identify and stop that program, or start the server with a different port."
171+
print(error_message)
172+
sys.exit(1)
173+
163174
app.run_server(mode=mode, **kwargs)
164175

165176
def stop_server(self, warn: bool = True):

0 commit comments

Comments
 (0)