-
-
Notifications
You must be signed in to change notification settings - Fork 531
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
pn.cache not working with async code: RuntimeError: cannot reuse already awaited coroutine #4236
Comments
WorkaroundInstead of using async def get_client():
if not "dask-client" in pn.state.cache:
pn.state.cache["dask-client"]=await Client(asynchronous=True)
return pn.state.cache["dask-client"] |
Just experienced this again when working on panel-chat-examples and trying to make |
The cache presumably should cache the awaitable but the return value of the awaitable. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm trying to contribute a guide on Panel+Dask in #4234.
I assume its best to use Dask
asynchronously
, because then you can off load computation to the dask cluster while still keeping your application responsive.Then I need a way to instantiate and share the async Dask client that work both in a notebook when people are experimenting and on the server. I assume its best to instantiate the client once and then share it across sessions.
In the notebook you can just do
client = await Client(asynchronously)
in a cell. But in a script running on the server you cannot useawait
outside of a function. If I do I get I get an error saying this is not possible.So instead I think I can just use
pn.cache
to instantiate once and then share. But this does not work.The second time you click the
Submit
button you getPlease make
pn.cache
work withasync
too or provide a seperatepn.async_cache
function.The text was updated successfully, but these errors were encountered: