What kind of tasks to use Asyncify for? #107
Unanswered
MarcSkovMadsen
asked this question in
Questions
Replies: 1 comment
-
I am using asyncer with panel trying to follow the docs you wrote, assuming it's https://panel.holoviz.org/how_to/concurrency/sync_to_async.html I am adding async functions to my panel app for the first time. I have existing data-fetch-and-format functions which call an API using the requests library. These functions are not async and are decorated with @pn.cache Here is what my code looks like: class MyClass:
def __init__(self):
... # stuff
self.lock = asyncio.Lock()
async def data_fetch_method(self, args):
async with self.lock:
table1_task = asyncio.create_task( asyncer.asyncify( get_from_table_1 )( args))
table2_task = asyncio.create_task( asyncer.asyncify( get_from_table_2)(args))
self.table1_data, self.table2_data = asyncio.gather( table1_task, table2_task) The questions I don't think the docs answer/demonstrate:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First Check
Description
I would like to describe
Asyncer
andasyncify
in theasync
documentation of HoloViz Panel as a very useful tool.If possible I would like to guide my users as to when
asyncify
is a great solution. I had hoped to find this information in theAsyncer
docs. But was not able to.What kind of tasks does
àsyncify
work best with? And why? How can I best guide the users of Panel?Additional Context
Our users typical use case is that they
Panel runs on top of the Bokeh/ Tornado server and really shines when you start using async. But most of the code our users use is sync code. So being able to easily turn that into async code is very valuable.
Normally its recommended to use
async
for io bound tasks and not cpu bound tasks. But in my experience it can be beneficial to use it with Panel for both io and cpu bound tasks. And that is also what I would recommend our users until I know better :-)Finally I would recommend my users to send tasks to Dask asynchronously if they start experiencing that they have too many cpu bound, async tasks running in the Panel server.
Beta Was this translation helpful? Give feedback.
All reactions