Issue
When I call a coroutine without awaiting, in addition to a message warning me I have not awaited the coroutine, I also get the following warning message:
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
I know how to fix this i.e. by awaiting the coroutine (and I do see a lot of questions about this warning, but all the answers are how to fix it; my goal is to understand it; please don't mark my question as duplicate if possible :) ); in particular, what I'd really like to understand is:
- What is tracemalloc? How do I enable it?
- What is the object allocation traceback?
- How is it related to coroutines? and, in particular
- Why is there a warning suggesting to enable tracemalloc when I don't await a coroutine?
My goal in asking this is understanding the details and inner-workings of asyncio better.
Solution
- What is tracemalloc? How do I enable it?
tracemalloc is a module that is used to debug memory allocation in python
you can enable it by setting PYTHONTRACEMALLOC environment variable to 1
check the docs for more info Tracemalloc docs
- What is the object allocation traceback
It's a way how python manages memory and allocates memory for it's objects
- Why is there a warning suggesting to enable tracemalloc when I don't await a coroutine?
I guess this is because memory is allocated and never used properly so we get loss of resources i.e memory leak
Answered By - Alex Ivashka
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.