panel icon indicating copy to clipboard operation
panel copied to clipboard

Fix `stop` button for sync

Open ahuang11 opened this issue 1 year ago • 1 comments

As Philipp mentioned https://github.com/holoviz/panel/issues/6295#issuecomment-1924471058, "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.

https://github.com/holoviz/panel/assets/15331990/22830b32-65dc-40d3-8595-da61be4361ef

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 avatar Feb 06 '24 06:02 ahuang11

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 :warning:
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%) :arrow_up:

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

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Feb 08 '24 07:02 codecov[bot]

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

philippjfr avatar Feb 27 '24 17:02 philippjfr