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


Python test_support.gc_collect方法代码示例

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


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

示例1: test_destructor

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import gc_collect [as 别名]
def test_destructor(self):
        record = []
        class MyFileIO(self.FileIO):
            def __del__(self):
                record.append(1)
                try:
                    f = super(MyFileIO, self).__del__
                except AttributeError:
                    pass
                else:
                    f()
            def close(self):
                record.append(2)
                super(MyFileIO, self).close()
            def flush(self):
                record.append(3)
                super(MyFileIO, self).flush()
        f = MyFileIO(support.TESTFN, "wb")
        f.write(b"xxx")
        del f
        support.gc_collect()
        self.assertEqual(record, [1, 2, 3])
        with self.open(support.TESTFN, "rb") as f:
            self.assertEqual(f.read(), b"xxx") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:26,代码来源:test_io.py

示例2: test_IOBase_finalize

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import gc_collect [as 别名]
def test_IOBase_finalize(self):
        # Issue #12149: segmentation fault on _PyIOBase_finalize when both a
        # class which inherits IOBase and an object of this class are caught
        # in a reference cycle and close() is already in the method cache.
        class MyIO(self.IOBase):
            def close(self):
                pass

        # create an instance to populate the method cache
        MyIO()
        obj = MyIO()
        obj.obj = obj
        wr = weakref.ref(obj)
        del MyIO
        del obj
        support.gc_collect()
        self.assertIsNone(wr(), wr) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:test_io.py

示例3: test_override_destructor

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import gc_collect [as 别名]
def test_override_destructor(self):
        record = []
        class MyTextIO(self.TextIOWrapper):
            def __del__(self):
                record.append(1)
                try:
                    f = super(MyTextIO, self).__del__
                except AttributeError:
                    pass
                else:
                    f()
            def close(self):
                record.append(2)
                super(MyTextIO, self).close()
            def flush(self):
                record.append(3)
                super(MyTextIO, self).flush()
        b = self.BytesIO()
        t = MyTextIO(b, encoding="ascii")
        del t
        support.gc_collect()
        self.assertEqual(record, [1, 2, 3]) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:24,代码来源:test_io.py

示例4: test_blockingioerror

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import gc_collect [as 别名]
def test_blockingioerror(self):
        # Various BlockingIOError issues
        self.assertRaises(TypeError, self.BlockingIOError)
        self.assertRaises(TypeError, self.BlockingIOError, 1)
        self.assertRaises(TypeError, self.BlockingIOError, 1, 2, 3, 4)
        self.assertRaises(TypeError, self.BlockingIOError, 1, "", None)
        b = self.BlockingIOError(1, "")
        self.assertEqual(b.characters_written, 0)
        class C(unicode):
            pass
        c = C("")
        b = self.BlockingIOError(1, c)
        c.b = b
        b.c = c
        wr = weakref.ref(c)
        del c, b
        support.gc_collect()
        self.assertIsNone(wr(), wr) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:20,代码来源:test_io.py

示例5: test_weakrefs

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import gc_collect [as 别名]
def test_weakrefs(self):
        # Testing weak references...
        import weakref
        class C(object):
            pass
        c = C()
        r = weakref.ref(c)
        self.assertEqual(r(), c)
        del c
        test_support.gc_collect()
        self.assertEqual(r(), None)
        del r
        class NoWeak(object):
            __slots__ = ['foo']
        no = NoWeak()
        try:
            weakref.ref(no)
        except TypeError, msg:
            self.assertIn("weak reference", str(msg)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:21,代码来源:test_descr.py

示例6: test_cache_leak

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import gc_collect [as 别名]
def test_cache_leak(self):
        # See issue #2521.
        class A(object):
            __metaclass__ = abc.ABCMeta
            @abc.abstractmethod
            def f(self):
                pass
        class C(A):
            def f(self):
                A.f(self)
        r = weakref.ref(C)
        # Trigger cache.
        C().f()
        del C
        test_support.gc_collect()
        self.assertEqual(r(), None) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_abc.py

示例7: test_IOBase_finalize

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import gc_collect [as 别名]
def test_IOBase_finalize(self):
        # Issue #12149: segmentation fault on _PyIOBase_finalize when both a
        # class which inherits IOBase and an object of this class are caught
        # in a reference cycle and close() is already in the method cache.
        class MyIO(self.IOBase):
            def close(self):
                pass

        # create an instance to populate the method cache
        MyIO()
        obj = MyIO()
        obj.obj = obj
        wr = weakref.ref(obj)
        del MyIO
        del obj
        support.gc_collect()
        self.assertTrue(wr() is None, wr) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:19,代码来源:test_io.py

示例8: test_blockingioerror

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import gc_collect [as 别名]
def test_blockingioerror(self):
        # Various BlockingIOError issues
        self.assertRaises(TypeError, self.BlockingIOError)
        self.assertRaises(TypeError, self.BlockingIOError, 1)
        self.assertRaises(TypeError, self.BlockingIOError, 1, 2, 3, 4)
        self.assertRaises(TypeError, self.BlockingIOError, 1, "", None)
        b = self.BlockingIOError(1, "")
        self.assertEqual(b.characters_written, 0)
        class C(unicode):
            pass
        c = C("")
        b = self.BlockingIOError(1, c)
        c.b = b
        b.c = c
        wr = weakref.ref(c)
        del c, b
        support.gc_collect()
        self.assertTrue(wr() is None, wr) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:20,代码来源:test_io.py

示例9: test_weakrefs

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import gc_collect [as 别名]
def test_weakrefs(self):
        # Testing weak references...
        import weakref
        class C(object):
            pass
        c = C()
        r = weakref.ref(c)
        self.assertEqual(r(), c)
        del c
        test_support.gc_collect()
        self.assertEqual(r(), None)
        del r
        class NoWeak(object):
            __slots__ = ['foo']
        no = NoWeak()
        try:
            weakref.ref(no)
        except TypeError, msg:
            self.assertTrue(str(msg).find("weak reference") >= 0) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:21,代码来源:test_descr.py

示例10: test_delete_hook

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import gc_collect [as 别名]
def test_delete_hook(self):
        # Testing __del__ hook...
        log = []
        class C(object):
            def __del__(self):
                log.append(1)
        c = C()
        self.assertEqual(log, [])
        del c
        test_support.gc_collect()
        self.assertEqual(log, [1])

        class D(object): pass
        d = D()
        try: del d[0]
        except TypeError: pass
        else: self.fail("invalid del() didn't raise TypeError") 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:19,代码来源:test_descr.py

示例11: _assert_no_pending_threads

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import gc_collect [as 别名]
def _assert_no_pending_threads(self, group, msg):
        # Ensure __del__ finalizers are called on sockets. Two things to note:
        # 1. It takes two collections for finalization to run.
        # 2. gc.collect() is only advisory to the JVM, never mandatory. Still 
        #    it usually seems to happen under light load.

        # Wait up to one second for there not to be pending threads

        for i in xrange(10):
            pending_threads = _check_threadpool_for_pending_threads(group)
            if len(pending_threads) == 0:
                break
            test_support.gc_collect()
            
        if pending_threads:
            print "Pending threads in Netty msg={} pool={}".format(msg, pprint.pformat(pending_threads)) 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:18,代码来源:test_socket.py

示例12: test_weakref__sock

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import gc_collect [as 别名]
def test_weakref__sock(self):
        s = socket.socket()._sock
        w = weakref.ref(s)
        self.assertIs(w(), s)
        del s
        test_support.gc_collect()
        self.assertIsNone(w()) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_socket.py

示例13: _check_base_destructor

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import gc_collect [as 别名]
def _check_base_destructor(self, base):
        record = []
        class MyIO(base):
            def __init__(self):
                # This exercises the availability of attributes on object
                # destruction.
                # (in the C version, close() is called by the tp_dealloc
                # function, not by __del__)
                self.on_del = 1
                self.on_close = 2
                self.on_flush = 3
            def __del__(self):
                record.append(self.on_del)
                try:
                    f = super(MyIO, self).__del__
                except AttributeError:
                    pass
                else:
                    f()
            def close(self):
                record.append(self.on_close)
                super(MyIO, self).close()
            def flush(self):
                record.append(self.on_flush)
                super(MyIO, self).flush()
        f = MyIO()
        del f
        support.gc_collect()
        self.assertEqual(record, [1, 2, 3]) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:31,代码来源:test_io.py

示例14: test_garbage_collection

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import gc_collect [as 别名]
def test_garbage_collection(self):
        # FileIO objects are collected, and collecting them flushes
        # all data to disk.
        f = self.FileIO(support.TESTFN, "wb")
        f.write(b"abcxxx")
        f.f = f
        wr = weakref.ref(f)
        del f
        support.gc_collect()
        self.assertIsNone(wr(), wr)
        with self.open(support.TESTFN, "rb") as f:
            self.assertEqual(f.read(), b"abcxxx") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:14,代码来源:test_io.py

示例15: test_nonbuffered_textio

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import gc_collect [as 别名]
def test_nonbuffered_textio(self):
        with warnings.catch_warnings(record=True) as recorded:
            with self.assertRaises(ValueError):
                self.open(support.TESTFN, 'w', buffering=0)
            support.gc_collect()
        self.assertEqual(recorded, []) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:8,代码来源:test_io.py


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