简体   繁体   中英

What does "RuntimeWarning: Enable tracemalloc to get the object allocation traceback" mean? I know how to fix, looking for the meaning

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 ie 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.

  • 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 ie memory leak

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM