Skip to content
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

First go at using a free port instead of defaulting to 8050 #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ directly on a D-Wave quantum computer's quantum processing unit (QPU).

## Usage

Run `python app.py` and open http://127.0.0.1:8050/ in your browser. A
Run `python app.py`.
A URL of the form http://127.0.0.1:***** will be printed in the console.
Open in the url in your browser.
Comment on lines +31 to +32
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A URL of the form http://127.0.0.1:***** will be printed in the console.
Open in the url in your browser.
A URL of the form `http://127.0.0.1:*****` is printed in the console.
Open the URL in your browser.

Not commenting on the solution just on this particular phrasing :-)

dropdown menu is provided to choose the dataset.

To visualize feature redundancy, first activate the "Show redundancy" check box.
Expand Down
10 changes: 9 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# visit http://127.0.0.1:8050/ in your web browser.

import json
import socket

from dash import Dash, html, dcc, Input, Output, State
from dash.exceptions import PreventUpdate
Expand Down Expand Up @@ -307,6 +308,13 @@ def update_score_figure(feature_score_data, data_key):
return children


def find_free_port():
with socket.socket() as s:
s.bind(('', 0)) # Bind to a free port provided by the host.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might have unwanted effects in LeapIDE -- depending on (random) port chosen, user might not get a notification about port/service being available (bottom-right pop-up notification).

return s.getsockname()[1] # Return the port number assigned.


if __name__ == '__main__':
# Set dev_tools_ui=False or debug=False to disable the dev tools UI
app.run_server(debug=True, dev_tools_ui=False)
port = find_free_port()
app.run_server(debug=True, dev_tools_ui=False, port=port)