-
-
Notifications
You must be signed in to change notification settings - Fork 73
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
Conversation
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." | ||
print(error_message) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is print + sys.exit used? Isn't it clearer to raise an error with that error message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you are right here, but when I run a dash app twice on the same host and port I dont get an error message thrown, it just tells me the same message above and quits. Not sure if this is within flask or dash but would be good to check that against those two as well as fastapi. Definitely agree that swallowing the error and quitting isnt ideal, so maybe an upstream change could be welcome here wherever that implementation lies.
Another test I need to make is if dash has this same behavior in a notebook as we are seeing here (taking too long to let the user know that the port is already in use)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the other real reason I dont want to throw an error here is that this is just calling the upstream libraries and honestly shouldnt be this library's problem to catch that imo as all it does is resample really well. I will do some digging at some point today to confirm any assumptions in the above comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll have a look myself later this week (I guess we should look at dash & jupyter dash) :)
Would be amazing if this PR avoids the cases where it takes dash way too long to notify the users when the port is already used!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, just validated this PR! Seems to work as expected 🔥
My 5 cents about sys.exit vs raising an error; although throwing an error in these cases is not at all the responsibility of this library, I think calling sys.exit(0)
is arguable even worse. Hence, I would propose to raise an exception (OSError, with your error message - perhaps you could inlude self._host in the msg as well) - as this exception gets raised a lot quicker than the upstream exceptions we are talking about. Do you agree with this @jayceslesar?
In an ideal world we would fix the issue / weird behavior in the upstream library (but I do not seem to find quickly where these issues stem from)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I raised the error and for reference here is where it is implemented in werkzeug, which is the error we were/are seeing with this change https://github.com/pallets/werkzeug/blob/edef71c243e1e1396092f7b5f82ddad6c6f766cf/src/werkzeug/serving.py#L907
Hi @jayceslesar! Thanks for contributing, looks promising! 👏🏼 TODO:
|
Codecov Report
@@ Coverage Diff @@
## main #79 +/- ##
==========================================
- Coverage 98.11% 97.73% -0.39%
==========================================
Files 10 10
Lines 743 750 +7
==========================================
+ Hits 729 733 +4
- Misses 14 17 +3
Continue to review full report at Codecov.
|
also looks like this is the second time the failing test has failed on different python versions while the other two passed haha. Not a stranger to those kinds of tests |
Hi @jayceslesar I did some further digging today and found out why it takes (quite) some time before jupyter-dash throws an OSError when the address is already in use. In the As this apparently intended behavior of jupyter-dash, I'm not really keen on overwriting this in this library (as it is not at all our responsibility). What do you think of this? Or were you targeting another bug / issue with this PR (that I am missing at the moment)? Cheers, Jeroen |
I think taking no action is a fine way to deal with this -- I completely agree that it is not this libraries job to better handle how things are treated upstream. Feel free to close |
Good to close this and #73 ? |
I experienced (plotly-resampler 0.8.0) that this dash app error might keep "hanging" indefinitely, seems to be caused by a plotly/jupyter-dash#103 (comment) Will create a new issue for this later this day. |
closes #73.
In Dash if you try to do this you get an output like:
So we mimic that here.