Skip to content

Terminate generating events early if the session is closed #2783

Merged
freddyaboulton merged 4 commits into
mainfrom
2787-clean-up-load-events
Dec 12, 2022
Merged

Terminate generating events early if the session is closed #2783
freddyaboulton merged 4 commits into
mainfrom
2787-clean-up-load-events

Conversation

@freddyaboulton
Copy link
Copy Markdown
Collaborator

@freddyaboulton freddyaboulton commented Dec 9, 2022

Description

Fixes: #2781

The process_event method would never terminate even if the websocket was closed. This PR fixes that by checking which events in the batch still have open connections. If None, the task finishes.

To test, run the repro in the original issue. Also added a unit test.

Checklist:

  • I have performed a self-review of my own code
  • I have added a short summary of my change to the CHANGELOG.md
  • My code follows the style guidelines of this project
  • I have commented my code in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

A note about the CHANGELOG

Hello 👋 and thank you for contributing to Gradio!

All pull requests must update the change log located in CHANGELOG.md, unless the pull request is labeled with the "no-changelog-update" label.

Please add a brief summary of the change to the Upcoming Release > Full Changelog section of the CHANGELOG.md file and include
a link to the PR (formatted in markdown) and a link to your github profile (if you like). For example, "* Added a cool new feature by [@myusername](link-to-your-github-profile) in [PR 11111](https://github.com/gradio-app/gradio/pull/11111)".

If you would like to elaborate on your change further, feel free to include a longer explanation in the other sections.
If you would like an image/gif/video showcasing your feature, it may be best to edit the CHANGELOG file using the
GitHub web UI since that lets you upload files directly via drag-and-drop.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Dec 9, 2022

All the demos for this PR have been deployed at https://huggingface.co/spaces/gradio-pr-deploys/pr-2783-all-demos

@freddyaboulton freddyaboulton changed the title Clean up load events with every Terminate generating events early if the session is closed Dec 9, 2022
@freddyaboulton freddyaboulton marked this pull request as ready for review December 9, 2022 19:29
Copy link
Copy Markdown
Member

@abidlabs abidlabs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM @freddyaboulton! Awesome fix.

I'd add documentation for the every parameter to make it clear that the event only continues to run while the client's webpage stays open.

@freddyaboulton freddyaboulton force-pushed the 2787-clean-up-load-events branch from 60bfae8 to e220d22 Compare December 12, 2022 14:02
@freddyaboulton
Copy link
Copy Markdown
Collaborator Author

freddyaboulton commented Dec 12, 2022

Thank you for the review and suggestion @abidlabs ! Clarified the docs.

@freddyaboulton freddyaboulton merged commit 3672e17 into main Dec 12, 2022
@freddyaboulton freddyaboulton deleted the 2787-clean-up-load-events branch December 12, 2022 14:15
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.

Event handlers triggered with every are not cleaned up on page refresh

2 participants