当前位置: 首页>>代码示例>>Python>>正文


Python tracemalloc.get_object_traceback方法代码示例

本文整理汇总了Python中tracemalloc.get_object_traceback方法的典型用法代码示例。如果您正苦于以下问题:Python tracemalloc.get_object_traceback方法的具体用法?Python tracemalloc.get_object_traceback怎么用?Python tracemalloc.get_object_traceback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tracemalloc的用法示例。


在下文中一共展示了tracemalloc.get_object_traceback方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_set_traceback_limit

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import get_object_traceback [as 别名]
def test_set_traceback_limit(self):
        obj_size = 10

        tracemalloc.stop()
        self.assertRaises(ValueError, tracemalloc.start, -1)

        tracemalloc.stop()
        tracemalloc.start(10)
        obj2, obj2_traceback = allocate_bytes(obj_size)
        traceback = tracemalloc.get_object_traceback(obj2)
        self.assertEqual(len(traceback), 10)
        self.assertEqual(traceback, obj2_traceback)

        tracemalloc.stop()
        tracemalloc.start(1)
        obj, obj_traceback = allocate_bytes(obj_size)
        traceback = tracemalloc.get_object_traceback(obj)
        self.assertEqual(len(traceback), 1)
        self.assertEqual(traceback, obj_traceback) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:21,代码来源:test_tracemalloc.py

示例2: test_get_object_traceback

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import get_object_traceback [as 别名]
def test_get_object_traceback(self):
        tracemalloc.clear_traces()
        obj_size = 12345
        obj, obj_traceback = allocate_bytes(obj_size)
        traceback = tracemalloc.get_object_traceback(obj)
        self.assertEqual(traceback, obj_traceback) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:8,代码来源:test_tracemalloc.py

示例3: test_clear_traces

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import get_object_traceback [as 别名]
def test_clear_traces(self):
        obj, obj_traceback = allocate_bytes(123)
        traceback = tracemalloc.get_object_traceback(obj)
        self.assertIsNotNone(traceback)

        tracemalloc.clear_traces()
        traceback2 = tracemalloc.get_object_traceback(obj)
        self.assertIsNone(traceback2) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:10,代码来源:test_tracemalloc.py

示例4: fork_child

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import get_object_traceback [as 别名]
def fork_child(self):
        if not tracemalloc.is_tracing():
            return 2

        obj_size = 12345
        obj, obj_traceback = allocate_bytes(obj_size)
        traceback = tracemalloc.get_object_traceback(obj)
        if traceback is None:
            return 3

        # everything is fine
        return 0 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:14,代码来源:test_tracemalloc.py

示例5: _formatwarnmsg_impl

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import get_object_traceback [as 别名]
def _formatwarnmsg_impl(msg):
    s =  ("%s:%s: %s: %s\n"
          % (msg.filename, msg.lineno, msg.category.__name__,
             msg.message))

    if msg.line is None:
        try:
            import linecache
            line = linecache.getline(msg.filename, msg.lineno)
        except Exception:
            # When a warning is logged during Python shutdown, linecache
            # and the import machinery don't work anymore
            line = None
            linecache = None
    else:
        line = msg.line
    if line:
        line = line.strip()
        s += "  %s\n" % line

    if msg.source is not None:
        try:
            import tracemalloc
            tb = tracemalloc.get_object_traceback(msg.source)
        except Exception:
            # When a warning is logged during Python shutdown, tracemalloc
            # and the import machinery don't work anymore
            tb = None

        if tb is not None:
            s += 'Object allocated at (most recent call last):\n'
            for frame in tb:
                s += ('  File "%s", lineno %s\n'
                      % (frame.filename, frame.lineno))

                try:
                    if linecache is not None:
                        line = linecache.getline(frame.filename, frame.lineno)
                    else:
                        line = None
                except Exception:
                    line = None
                if line:
                    line = line.strip()
                    s += '    %s\n' % line
    return s

# Keep a reference to check if the function was replaced 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:50,代码来源:warnings.py

示例6: _formatwarnmsg_impl

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import get_object_traceback [as 别名]
def _formatwarnmsg_impl(msg):
    category = msg.category.__name__
    s =  f"{msg.filename}:{msg.lineno}: {category}: {msg.message}\n"

    if msg.line is None:
        try:
            import linecache
            line = linecache.getline(msg.filename, msg.lineno)
        except Exception:
            # When a warning is logged during Python shutdown, linecache
            # and the import machinery don't work anymore
            line = None
            linecache = None
    else:
        line = msg.line
    if line:
        line = line.strip()
        s += "  %s\n" % line

    if msg.source is not None:
        try:
            import tracemalloc
        # Logging a warning should not raise a new exception:
        # catch Exception, not only ImportError and RecursionError.
        except Exception:
            # don't suggest to enable tracemalloc if it's not available
            tracing = True
            tb = None
        else:
            tracing = tracemalloc.is_tracing()
            try:
                tb = tracemalloc.get_object_traceback(msg.source)
            except Exception:
                # When a warning is logged during Python shutdown, tracemalloc
                # and the import machinery don't work anymore
                tb = None

        if tb is not None:
            s += 'Object allocated at (most recent call last):\n'
            for frame in tb:
                s += ('  File "%s", lineno %s\n'
                      % (frame.filename, frame.lineno))

                try:
                    if linecache is not None:
                        line = linecache.getline(frame.filename, frame.lineno)
                    else:
                        line = None
                except Exception:
                    line = None
                if line:
                    line = line.strip()
                    s += '    %s\n' % line
        elif not tracing:
            s += (f'{category}: Enable tracemalloc to get the object '
                  f'allocation traceback\n')
    return s

# Keep a reference to check if the function was replaced 
开发者ID:bkerler,项目名称:android_universal,代码行数:61,代码来源:warnings.py


注:本文中的tracemalloc.get_object_traceback方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。