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

Fix stop button for sync #6312

Merged
merged 12 commits into from
Feb 27, 2024
Merged

Fix stop button for sync #6312

merged 12 commits into from
Feb 27, 2024

Conversation

ahuang11
Copy link
Contributor

@ahuang11 ahuang11 commented Feb 6, 2024

As Philipp mentioned #6295 (comment), "Generators really do not seem useful here, a generator function is blocking, therefore even if this did work you'd just get the final output and never see the intermediate outputs."

After, I realized the stop button didn't quite work for sync functions. For some reason, at some point in time, I thought loop.run_in_executor would prevent it from blocking the placeholder / stop clicks, like https://stackoverflow.com/questions/41063331/how-to-use-asyncio-with-existing-blocking-library, but I couldn't get it to work.

This PR hides the stop button if it's a sync function and immediately shows the placeholder.

Screen.Recording.2024-02-05.at.10.34.56.PM.mov
from time import sleep

import panel as pn

pn.extension()


def callback(contents: str, user: str, instance: pn.chat.ChatInterface):
    sleep(5)
    message = ""
    for char in "Echoing User: " + contents:
        sleep(0.05)
        message += char
        yield message


chat_interface = pn.chat.ChatInterface(callback=callback, placeholder_threshold=0.5)
chat_interface.send(
    "Enter a message in the TextInput below and receive an echo!",
    user="System",
    respond=False,
)
chat_interface.servable()

@ahuang11 ahuang11 requested a review from philippjfr February 6, 2024 06:37
Copy link

codecov bot commented Feb 8, 2024

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (d4a216e) 71.64% compared to head (6dcc8e5) 71.67%.

Files Patch % Lines
panel/tests/chat/test_feed.py 93.54% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6312      +/-   ##
==========================================
+ Coverage   71.64%   71.67%   +0.02%     
==========================================
  Files         305      305              
  Lines       45559    45602      +43     
==========================================
+ Hits        32642    32683      +41     
- Misses      12917    12919       +2     
Flag Coverage Δ
unitexamples-tests 71.67% <96.87%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ahuang11 ahuang11 changed the title Disable stop button for sync Fix stop button for sync Feb 19, 2024
@philippjfr
Copy link
Member

JupyterLite test execution is failing the UI tests, which is unrelated. Will merge.

@philippjfr philippjfr merged commit 013b1fb into main Feb 27, 2024
12 of 15 checks passed
@philippjfr philippjfr deleted the disable_stop_for_sync branch February 27, 2024 17:28
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.

2 participants