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
Stop running iterators when js client disconnects #7835
Conversation
🪼 branch checks and previews
Install Gradio from this PR pip install https://gradio-builds.s3.amazonaws.com/68608040ca8d10d38bb626ac969134afe4e50c50/gradio-4.23.0-py3-none-any.whl Install Gradio Python Client from this PR pip install "gradio-client @ git+https://github.com/gradio-app/gradio@68608040ca8d10d38bb626ac969134afe4e50c50#subdirectory=client/python" |
🦄 change detectedThis Pull Request includes changes to the following packages.
With the following changelog entry.
Maintainers or the PR author can modify the PR title to modify this entry.
|
131e866
to
aba293f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's revert these changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need this for the 2e2 test actually! I don't know how else to verify the server process stopped running
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah got it! We don't use this demo in any of our docs so it should be fine
demo/cancel_events/run.py
Outdated
for i in range(steps): | ||
print(f"Current step: {i}") | ||
log_file.write_text(f"Current step: {i}\n") | ||
time.sleep(0.5) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we make this faster? So that we could reduce the time that we have to wait in the test
time.sleep(0.5) | |
time.sleep(0.2) |
@@ -803,11 +803,11 @@ async def sse_stream(request: fastapi.Request): | |||
message=str(e), | |||
) | |||
response = process_msg(message) | |||
if response is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah so we already had the deletion logic in place, but it was never called?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea we yielded the response before the clean up logic happened so we never reached that point in the code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch
"../../demo/cancel_events/cancel_events_output_log.txt", | ||
"utf-8" | ||
); | ||
expect(data).not.toContain("Current step: 8"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's also ensure that at least one of the steps that should be logged are logged
expect(data).not.toContain("Current step: 8"); | |
expect(data).toContain("Current step: 1"); | |
expect(data).not.toContain("Current step: 8"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reasonable!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a few suggestions. Cool test!
aba293f
to
6860804
Compare
Thanks for the review @abidlabs ! I addressed your comments so will merge once ci passes |
Description
If you run an iterator event and close the page the python function will keep running in the backend.
To test, run the following demo, click the button and close the page. Things will still be being printed to the console in main. On this branch, they do not. Also added a playwright test for this.
🎯 PRs Should Target Issues
Before your create a PR, please check to see if there is an existing issue for this change. If not, please create an issue before you create this PR, unless the fix is very small.
Not adhering to this guideline will result in the PR being closed.
Tests
PRs will only be merged if tests pass on CI. To run the tests locally, please set up your Gradio environment locally and run the tests:
bash scripts/run_all_tests.sh
You may need to run the linters:
bash scripts/format_backend.sh
andbash scripts/format_frontend.sh