8000 Decorated async functions report 0 time · Issue #55 · realpython/codetiming · GitHub
[go: up one dir, main page]

Skip to content

Decorated async functions report 0 time #55

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

Open
rmaunder opened this issue Mar 22, 2025 · 0 comments
Open

Decorated async functions report 0 time #55

rmaunder opened this issue Mar 22, 2025 · 0 comments

Comments

@rmaunder
Copy link

Hi

This library is very handy but seems it can't be used with async fns - where it would be very helpful. Simple example:

import asyncio
import time
import codetiming

@codetiming.Timer(name="my_func", initial_text='Started...', text="{name} complete in {:.4f} secs")
def my_func():
  time.sleep(5)
  print('done')

@codetiming.Timer(name="my_async_func", initial_text='Started...', text="{name} complete in {:.4f} secs")
async def my_async_func():
  time.sleep(5)
  print('done')

my_func() # timing ok...

loop = asyncio.get_event_loop()
loop.run_until_complete(my_async_func()) # timing 0.0 sec

This gives output:

Started...
done
my_func complete in 5.0052 secs
Started...
my_async_func complete in 0.0000 secs
done

Is there a way to use it to correctly report the actual elapsed time for the async function somehow?

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

No branches or pull requests

1 participant
0