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

Support async functions on ParamMethod/ParamFunction #2964

Merged
merged 1 commit into from
Nov 30, 2021

Conversation

philippjfr
Copy link
Member

Allows an approach like this:

import aiohttp

widget = pn.widgets.IntSlider(start=0, end=10)

async def get_img(index):
    async with aiohttp.ClientSession() as session:
        async with session.get(f"https://picsum.photos/800/300?image={index}") as resp:
            return pn.pane.JPG(await resp.read())
            
pn.Column(widget, pn.bind(get_img, widget))

@philippjfr philippjfr added this to the v0.13.0 milestone Nov 30, 2021
@philippjfr philippjfr added the type: enhancement Minor feature or improvement to an existing feature label Nov 30, 2021
@codecov
Copy link

codecov bot commented Nov 30, 2021

Codecov Report

Merging #2964 (374436d) into master (1badb73) will decrease coverage by 0.01%.
The diff coverage is 53.84%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2964      +/-   ##
==========================================
- Coverage   83.13%   83.11%   -0.02%     
==========================================
  Files         190      190              
  Lines       24875    24885      +10     
==========================================
+ Hits        20680    20684       +4     
- Misses       4195     4201       +6     
Impacted Files Coverage Δ
panel/param.py 86.92% <53.84%> (-0.82%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1badb73...374436d. Read the comment docs.

@philippjfr
Copy link
Member Author

Linux 3.6 test failure is spurious.

@philippjfr philippjfr merged commit d6b315f into master Nov 30, 2021
@philippjfr philippjfr deleted the param_func_async branch November 30, 2021 13:58
@MarcSkovMadsen
Copy link
Collaborator

Panel will be the most "modern" package in Python :-)

@MarcSkovMadsen
Copy link
Collaborator

MarcSkovMadsen commented Nov 30, 2021

How would it work with pn.panel(pn.bind(get_img, widget), loading_indicator=True)? Would the loading indicator be shown while the image is being loading async? That would be awesome.

@philippjfr
Copy link
Member Author

Correct! Considering whether to just enable that by default.

@MarcSkovMadsen
Copy link
Collaborator

MarcSkovMadsen commented Nov 30, 2021

The problem is that if a function is fast, then trying to show the loading indicator actually slows down your application. Or at least it feels like that to the user. And often your function would be fast.

Somehow the loading indicator should first be started after maybe 0.5 seconds or so ??

@philippjfr
Copy link
Member Author

Good point, I think because of that it's probably best left up to the user. Don't want to be in the business of timing user callbacks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Minor feature or improvement to an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants