MCPcopy Index your code
hub / github.com/python/cpython / _test_finalize

Method _test_finalize

Lib/test/_test_multiprocessing.py:5073–5110  ·  view source on GitHub ↗
(cls, conn)

Source from the content-addressed store, hash-verified

5071
5072 @classmethod
5073 def _test_finalize(cls, conn):
5074 class Foo(object):
5075 pass
5076
5077 a = Foo()
5078 util.Finalize(a, conn.send, args=('a',))
5079 del a # triggers callback for a
5080 gc.collect() # For PyPy or other GCs.
5081
5082 b = Foo()
5083 close_b = util.Finalize(b, conn.send, args=('b',))
5084 close_b() # triggers callback for b
5085 close_b() # does nothing because callback has already been called
5086 del b # does nothing because callback has already been called
5087 gc.collect() # For PyPy or other GCs.
5088
5089 c = Foo()
5090 util.Finalize(c, conn.send, args=('c',))
5091
5092 d10 = Foo()
5093 util.Finalize(d10, conn.send, args=('d10',), exitpriority=1)
5094
5095 d01 = Foo()
5096 util.Finalize(d01, conn.send, args=('d01',), exitpriority=0)
5097 d02 = Foo()
5098 util.Finalize(d02, conn.send, args=('d02',), exitpriority=0)
5099 d03 = Foo()
5100 util.Finalize(d03, conn.send, args=('d03',), exitpriority=0)
5101
5102 util.Finalize(None, conn.send, args=('e',), exitpriority=-10)
5103
5104 util.Finalize(None, conn.send, args=('STOP',), exitpriority=-100)
5105
5106 # call multiprocessing's cleanup function then exit process without
5107 # garbage collecting locals
5108 util._exit_function()
5109 conn.close()
5110 os._exit(0)
5111
5112 @warnings_helper.ignore_fork_in_thread_deprecation_warnings()
5113 def test_finalize(self):

Callers

nothing calls this directly

Calls 4

FooClass · 0.70
collectMethod · 0.45
closeMethod · 0.45
_exitMethod · 0.45

Tested by

no test coverage detected