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

Use websockets to detect tab close #223

Merged
merged 18 commits into from
Oct 31, 2024
Merged

Use websockets to detect tab close #223

merged 18 commits into from
Oct 31, 2024

Conversation

danvk
Copy link
Owner

@danvk danvk commented Jul 16, 2024

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.

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.

@danvk danvk merged commit 9df5d2f into main Oct 31, 2024
2 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.

Closing diff window does not reliably terminate webdiff command
1 participant