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

gather information from async functions #1430

Closed
smmoosavi opened this issue Dec 28, 2020 · 7 comments · Fixed by #1993
Closed

gather information from async functions #1430

smmoosavi opened this issue Dec 28, 2020 · 7 comments · Fixed by #1993

Comments

@smmoosavi
Copy link

smmoosavi commented Dec 28, 2020

If some queries are executed in async mode, these queries are missing in the panel. How can we collect these?

data = asyncio.run(parallel_calc_aggregations(queryset, aggregations))

note1: I am using django-debug-toolbar via django-graphiql-debug-toolbar
note2: all queries are inside function wrapped by sync_to_async

The same issue exists when graphql ThreadExecutor is used. read more about graphql executors graphql-314

@tim-schilling
Copy link
Contributor

The toolbar currently does not support async and the collection of statistics is tightly coupled to a request. If you do end up diving into how to modify the toolbar to collect this information, we'd appreciate any conclusions or findings of yours.

@smmoosavi
Copy link
Author

smmoosavi commented Dec 28, 2020

Is there any decorator function we can add around these functions and collect data required by debug-toolbar?

@collect_debug_toolbar_data
def get_data():
  # pure django

async def async_get_data():
      return await sync_to_async(get_data, thread_sensitive=False)()

async def parallel_get_data():
  return await asyncio.gather(async_get_data(), async_get_data(), async_get_data())

data = asyncio.run(parallel_get_data())

@tim-schilling
Copy link
Contributor

Currently the only API for collecting the data is done via the middleware and the methods on the panels themselves.

@smmoosavi
Copy link
Author

smmoosavi commented Dec 28, 2020

maybe it's possible to wrap/runtime patch sync_to_async. all async function using django orm should use this function and without sync_to_async function causing error.

def sync_to_async(func=None, thread_sensitive=True):
    if func is None:
        return lambda f: SyncToAsync(f, thread_sensitive=thread_sensitive)
    return SyncToAsync(func, thread_sensitive=thread_sensitive)

the func argument is a simple sync function

@michaelurban
Copy link

Until async views are supported can the toolbar at least be kept from erroring out on aync views?

@tim-schilling
Copy link
Contributor

@michaelurban that's a good idea. Or at least log some type of message. Would you be able to write up a PR to introduce that feature?

@michaelurban
Copy link

@tim-schilling Sorry, I don't have the time. I'm working 80+ hour weeks for the foreseeable future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants