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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions panel/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@
Defines the Param pane which converts Parameterized classes into a
set of widgets.
"""
import inspect
import itertools
import json
import os
import sys
import json
import types
import inspect
import itertools

from collections import OrderedDict, defaultdict, namedtuple
from contextlib import contextmanager
from functools import partial
from six import string_types

import param

from param.parameterized import classlist, discard_events

from .io import init_doc, state
from .io.server import async_execute
from .layout import Column, Panel, Row, Spacer, Tabs
from .pane.base import PaneBase, ReplacementPane
from .util import (
Expand Down Expand Up @@ -748,6 +750,13 @@ def eval(self, function):
kwargs = {n: getattr(dep.owner, dep.name) for n, dep in kw_deps.items()}
return function(*args, **kwargs)

async def _eval_async(self, awaitable):
try:
new_object = await awaitable
self._update_inner(new_object)
finally:
self._inner_layout.loading = False

def _replace_pane(self, *args, force=False):
self._evaled = bool(self._models) or force or not self.lazy
if self._evaled:
Expand All @@ -757,6 +766,9 @@ def _replace_pane(self, *args, force=False):
new_object = Spacer()
else:
new_object = self.eval(self.object)
if inspect.isawaitable(new_object):
async_execute(partial(self._eval_async, new_object))
return
self._update_inner(new_object)
finally:
self._inner_layout.loading = False
Expand Down