http://localhost:8050 reflects app1. While app1 is running, I launch another app using the same port:
app2.py:
#!/usr/bin/env python
import dash
import dash_html_components as html
import dash_core_components as dcc
from dash.dependencies import Input, Output
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.layout = html.Div([
'The dropdown menu is vanished',
html.Br(),
'Sample HTML'
])
app.run_server(debug=False, port= 8050, host= 'localhost')
When refreshed, http://localhost:8050 is not overwritten to reflect app2. This behavior would have been fine if we could get an error.
The question-- is it possible to raise an error from dash if the port is already in use? A way around would be to check the port at the beginning of each app:
import socket
s= socket.socket
s.connect(('localhost',8050))
# if not is use, would give `ConnectionRefusedError`
# otherwise none
It looks like the error comes up on Linux but not on Windows:
* Serving Flask app "app2" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
Traceback (most recent call last):
File "./app2.py", line 20, in <module>
app.run_server(debug=False, port= 8050, host= 'localhost')
File "/home/avatar/miniconda3/lib/python3.7/site-packages/dash/dash.py", line 1574, in run_server
self.server.run(host=host, port=port, debug=debug, **flask_run_options)
File "/home/avatar/miniconda3/lib/python3.7/site-packages/flask/app.py", line 990, in run
run_simple(host, port, self, **options)
File "/home/avatar/miniconda3/lib/python3.7/site-packages/werkzeug/serving.py", line 1052, in run_simple
inner()
File "/home/avatar/miniconda3/lib/python3.7/site-packages/werkzeug/serving.py", line 1005, in inner
fd=fd,
File "/home/avatar/miniconda3/lib/python3.7/site-packages/werkzeug/serving.py", line 848, in make_server
host, port, app, request_handler, passthrough_errors, ssl_context, fd=fd
File "/home/avatar/miniconda3/lib/python3.7/site-packages/werkzeug/serving.py", line 740, in __init__
HTTPServer.__init__(self, server_address, handler)
File "/home/avatar/miniconda3/lib/python3.7/socketserver.py", line 452, in __init__
self.server_bind()
File "/home/avatar/miniconda3/lib/python3.7/http/server.py", line 137, in server_bind
socketserver.TCPServer.server_bind(self)
File "/home/avatar/miniconda3/lib/python3.7/socketserver.py", line 466, in server_bind
self.socket.bind(self.server_address)
OSError: [Errno 98] Address already in use