Use websockets to detect tab close #223
Merged
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.
Hopefully fixes #66
Running a websockets server and Python
http.server
simultaneously proved difficult, so I wound up moving the app entirely over to aiohttp, which includes built-in websocket support on the same port as your http server. This has been reliable so far.A future extension (mostly useful for debugging) would be to only shut down after all websocket connections have closed, in case you have multiple tabs open.
After going down a bunch of dead ends, I found that
signal.raise_signal(signal.SIGINT)
was the most effective way to shut down the aiohttp server.Downsides:
I'm going to use this locally for maybe a month and see how reliable it is before merging.
Update ~3.5 months later: this is extremely reliable about terminating the process. The one downside I've noticed is that if I want to kill webdiff from the terminal, I have to Ctrl-C it twice.