webdiff
webdiff copied to clipboard
Use websockets to detect tab close
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:
- It's likely that this breaks Windows support.
- aiohttp does pull in some transitive dependencies, but I think they're pretty light.
I'm going to use this locally for maybe a month and see how reliable it is before merging.