Tin mới
trace — Trace or track Python statement execution
Software Packaging and Distribution
Python documentation for the current stable release
The tracemalloc module is a debug tool to trace memory blocks allocated by Python. It provides the following information:
collections: Container datatypes
We can see that Python loaded 4855 KiB data (bytecode and constants) from modules and that the collections module allocated 244 KiB to build namedtuple types.
linecache: Provides random access to individual lines from text files.
Example of output before/after running some tests of the Python test suite:
importlib: The implementation of the import machinery.
Code to display the traceback of the biggest memory block:
doctest: Test pieces of code within docstrings.
Code to display the traceback of the biggest memory block:
Record the current and peak size of all traced memory blocks¶
The following code computes two sums like 0 + 1 + 2 + ... inefficiently, by creating a list of those numbers. This list consumes a lot of memory temporarily. We can use get_traced_memory() and reset_peak() to observe the
Get the traceback where the Python object obj was allocated. Return a Traceback instance, or None if the tracemalloc module is not tracing memory allocations or did not trace the allocation of the object.
subprocess: Subprocess management.
Filter(True, subprocess.__file__) only includes traces of the subprocess module
Format the traceback as a list of lines. Use the linecache module to retrieve lines from the source code. If limit is set, format the limit most recent frames if limit is positive. Otherwise, format the abs(limit) oldest