fix(#170): wait for the IOLoop to stop before attempting to close it #276
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello!
Thank you for this amazing library 🤩 !
It works really well when watching static assets and templates, however I noticed that changes to
.py
files fails due to a runtime error. This issue has been previously recorded in #170, and marked as "needs more info". In my Flask project, I'm able to reproduce it continuously on every change to a .py file in the project.After following the comments on the ticket, I realized the technique to restart tornado can be improved in order to avoid the runtime error. This PR introduces a slight change in the order of disposing of resources:
From the docs
IOLoop.instance().start()
does not return until the program callsIOLoop.instance().stop()
.IOLoop.instance().stop()
returns immediately, however it takes some time for the loop to be shutdown. A complete stop is fact only when the call toIOLoop.instance().start()
returns.So to avoid the crash, the call to
.close()
must be after the call to.start()
has returned.ℹ️ The tornado docs include an additional recommendation on how to handle this scenario differently (without having to reboot the loop) but that may have other unintended side effects, so I didn't consider it further.
ℹ️ My setup is as follows: