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

added feature to automatically change port #2867

Merged
merged 4 commits into from Mar 26, 2024

Conversation

wassafshahzad
Copy link
Contributor

All Submissions:

  • Have you followed the guidelines stated in CONTRIBUTING.md file?
  • Have you checked to ensure there aren't any other open Pull Requests for the desired changed?

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

New Feature Submission:

  • Does your submission pass the tests?
  • Have you linted your code locally prior to submission?

Changes To Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Description

Added feature to automatically change port if currently one is used.

Linked Issue

Closes #2857

@srikary12
Copy link

I've implemented something similar, but added just auto select functionality after 5 sec instead of by default. You can find the changes here https://github.com/srikary12/reflex-dev

@wassafshahzad
Copy link
Contributor Author

wassafshahzad commented Mar 16, 2024

I've implemented something similar, but added just auto select functionality after 5 sec instead of by default. You can find the changes here https://github.com/srikary12/reflex-dev
@srikary12
Are you shadowing the repo ? if not you should first have the issue assigned to your self before starting and then create a pull request. Other then that I have taken a look at your changes. You are using sockets to check if the port is connected or not, which is not needed since we already have a function called is_process_on_port which informs us if the port is already occupied.

I do like you idea of informing the user before auto selecting the ports but I believe it would be better to have a property in the config something like "auto_select_port: Bool". Since asking the user change_or_terminate_port is a bit redundant in most case as the user can just manually enter a port.
Still good effort.

Copy link
Collaborator

@masenf masenf left a comment

Choose a reason for hiding this comment

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

lgtm

new_port = str(int(port) + 1)
if is_process_on_port(new_port):
return change_port(new_port)
return new_port
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think we should print an info message here, similar to the one that was removed

            console.info(
                f"The {_type} will run on port [bold underline]{new_port}[/bold underline]."
            )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure will do

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@masenf Done

Copy link
Contributor

@picklelo picklelo left a comment

Choose a reason for hiding this comment

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

Works great for me, this is a sweet improvement!

@picklelo picklelo merged commit 15dc7f4 into reflex-dev:main Mar 26, 2024
62 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[REF-2220] reflex run should automatically select new port if default is taken
4 participants