Skip to content

Mimic Dash error if running app on port already in use #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions plotly_resampler/figure_resampler/figure_resampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

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

import sys
import socket
import warnings
from typing import Tuple

Expand Down Expand Up @@ -160,6 +162,14 @@ def show_dash(
self._host = kwargs.get("host", "127.0.0.1")
self._port = kwargs.get("port", "8050")

# check if self._port is already in use
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
if s.connect_ex((self._host, int(self._port))) == 0:
error_message = "Address already in use\n" \
f"Port {self._port} is in use by another program. " \
"Either identify and stop that program, or start the server with a different port."
raise socket.error(error_message)

app.run_server(mode=mode, **kwargs)

def stop_server(self, warn: bool = True):
Expand Down