test_gc.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. import unittest
  2. from test.test_support import verbose, run_unittest, start_threads
  3. import sys
  4. import time
  5. import gc
  6. import weakref
  7. try:
  8. import threading
  9. except ImportError:
  10. threading = None
  11. ### Support code
  12. ###############################################################################
  13. # Bug 1055820 has several tests of longstanding bugs involving weakrefs and
  14. # cyclic gc.
  15. # An instance of C1055820 has a self-loop, so becomes cyclic trash when
  16. # unreachable.
  17. class C1055820(object):
  18. def __init__(self, i):
  19. self.i = i
  20. self.loop = self
  21. class GC_Detector(object):
  22. # Create an instance I. Then gc hasn't happened again so long as
  23. # I.gc_happened is false.
  24. def __init__(self):
  25. self.gc_happened = False
  26. def it_happened(ignored):
  27. self.gc_happened = True
  28. # Create a piece of cyclic trash that triggers it_happened when
  29. # gc collects it.
  30. self.wr = weakref.ref(C1055820(666), it_happened)
  31. ### Tests
  32. ###############################################################################
  33. class GCTests(unittest.TestCase):
  34. def test_list(self):
  35. l = []
  36. l.append(l)
  37. gc.collect()
  38. del l
  39. self.assertEqual(gc.collect(), 1)
  40. def test_dict(self):
  41. d = {}
  42. d[1] = d
  43. gc.collect()
  44. del d
  45. self.assertEqual(gc.collect(), 1)
  46. def test_tuple(self):
  47. # since tuples are immutable we close the loop with a list
  48. l = []
  49. t = (l,)
  50. l.append(t)
  51. gc.collect()
  52. del t
  53. del l
  54. self.assertEqual(gc.collect(), 2)
  55. def test_class(self):
  56. class A:
  57. pass
  58. A.a = A
  59. gc.collect()
  60. del A
  61. self.assertNotEqual(gc.collect(), 0)
  62. def test_newstyleclass(self):
  63. class A(object):
  64. pass
  65. gc.collect()
  66. del A
  67. self.assertNotEqual(gc.collect(), 0)
  68. def test_instance(self):
  69. class A:
  70. pass
  71. a = A()
  72. a.a = a
  73. gc.collect()
  74. del a
  75. self.assertNotEqual(gc.collect(), 0)
  76. def test_newinstance(self):
  77. class A(object):
  78. pass
  79. a = A()
  80. a.a = a
  81. gc.collect()
  82. del a
  83. self.assertNotEqual(gc.collect(), 0)
  84. class B(list):
  85. pass
  86. class C(B, A):
  87. pass
  88. a = C()
  89. a.a = a
  90. gc.collect()
  91. del a
  92. self.assertNotEqual(gc.collect(), 0)
  93. del B, C
  94. self.assertNotEqual(gc.collect(), 0)
  95. A.a = A()
  96. del A
  97. self.assertNotEqual(gc.collect(), 0)
  98. self.assertEqual(gc.collect(), 0)
  99. def test_method(self):
  100. # Tricky: self.__init__ is a bound method, it references the instance.
  101. class A:
  102. def __init__(self):
  103. self.init = self.__init__
  104. a = A()
  105. gc.collect()
  106. del a
  107. self.assertNotEqual(gc.collect(), 0)
  108. def test_finalizer(self):
  109. # A() is uncollectable if it is part of a cycle, make sure it shows up
  110. # in gc.garbage.
  111. class A:
  112. def __del__(self): pass
  113. class B:
  114. pass
  115. a = A()
  116. a.a = a
  117. id_a = id(a)
  118. b = B()
  119. b.b = b
  120. gc.collect()
  121. del a
  122. del b
  123. self.assertNotEqual(gc.collect(), 0)
  124. for obj in gc.garbage:
  125. if id(obj) == id_a:
  126. del obj.a
  127. break
  128. else:
  129. self.fail("didn't find obj in garbage (finalizer)")
  130. gc.garbage.remove(obj)
  131. def test_finalizer_newclass(self):
  132. # A() is uncollectable if it is part of a cycle, make sure it shows up
  133. # in gc.garbage.
  134. class A(object):
  135. def __del__(self): pass
  136. class B(object):
  137. pass
  138. a = A()
  139. a.a = a
  140. id_a = id(a)
  141. b = B()
  142. b.b = b
  143. gc.collect()
  144. del a
  145. del b
  146. self.assertNotEqual(gc.collect(), 0)
  147. for obj in gc.garbage:
  148. if id(obj) == id_a:
  149. del obj.a
  150. break
  151. else:
  152. self.fail("didn't find obj in garbage (finalizer)")
  153. gc.garbage.remove(obj)
  154. def test_function(self):
  155. # Tricky: f -> d -> f, code should call d.clear() after the exec to
  156. # break the cycle.
  157. d = {}
  158. exec("def f(): pass\n") in d
  159. gc.collect()
  160. del d
  161. self.assertEqual(gc.collect(), 2)
  162. def test_frame(self):
  163. def f():
  164. frame = sys._getframe()
  165. gc.collect()
  166. f()
  167. self.assertEqual(gc.collect(), 1)
  168. def test_saveall(self):
  169. # Verify that cyclic garbage like lists show up in gc.garbage if the
  170. # SAVEALL option is enabled.
  171. # First make sure we don't save away other stuff that just happens to
  172. # be waiting for collection.
  173. gc.collect()
  174. # if this fails, someone else created immortal trash
  175. self.assertEqual(gc.garbage, [])
  176. L = []
  177. L.append(L)
  178. id_L = id(L)
  179. debug = gc.get_debug()
  180. gc.set_debug(debug | gc.DEBUG_SAVEALL)
  181. del L
  182. gc.collect()
  183. gc.set_debug(debug)
  184. self.assertEqual(len(gc.garbage), 1)
  185. obj = gc.garbage.pop()
  186. self.assertEqual(id(obj), id_L)
  187. def test_del(self):
  188. # __del__ methods can trigger collection, make this to happen
  189. thresholds = gc.get_threshold()
  190. gc.enable()
  191. gc.set_threshold(1)
  192. class A:
  193. def __del__(self):
  194. dir(self)
  195. a = A()
  196. del a
  197. gc.disable()
  198. gc.set_threshold(*thresholds)
  199. def test_del_newclass(self):
  200. # __del__ methods can trigger collection, make this to happen
  201. thresholds = gc.get_threshold()
  202. gc.enable()
  203. gc.set_threshold(1)
  204. class A(object):
  205. def __del__(self):
  206. dir(self)
  207. a = A()
  208. del a
  209. gc.disable()
  210. gc.set_threshold(*thresholds)
  211. # The following two tests are fragile:
  212. # They precisely count the number of allocations,
  213. # which is highly implementation-dependent.
  214. # For example:
  215. # - disposed tuples are not freed, but reused
  216. # - the call to assertEqual somehow avoids building its args tuple
  217. def test_get_count(self):
  218. # Avoid future allocation of method object
  219. assertEqual = self._baseAssertEqual
  220. gc.collect()
  221. assertEqual(gc.get_count(), (0, 0, 0))
  222. a = dict()
  223. # since gc.collect(), we created two objects:
  224. # the dict, and the tuple returned by get_count()
  225. assertEqual(gc.get_count(), (2, 0, 0))
  226. def test_collect_generations(self):
  227. # Avoid future allocation of method object
  228. assertEqual = self.assertEqual
  229. gc.collect()
  230. a = dict()
  231. gc.collect(0)
  232. assertEqual(gc.get_count(), (0, 1, 0))
  233. gc.collect(1)
  234. assertEqual(gc.get_count(), (0, 0, 1))
  235. gc.collect(2)
  236. assertEqual(gc.get_count(), (0, 0, 0))
  237. def test_trashcan(self):
  238. class Ouch:
  239. n = 0
  240. def __del__(self):
  241. Ouch.n = Ouch.n + 1
  242. if Ouch.n % 17 == 0:
  243. gc.collect()
  244. # "trashcan" is a hack to prevent stack overflow when deallocating
  245. # very deeply nested tuples etc. It works in part by abusing the
  246. # type pointer and refcount fields, and that can yield horrible
  247. # problems when gc tries to traverse the structures.
  248. # If this test fails (as it does in 2.0, 2.1 and 2.2), it will
  249. # most likely die via segfault.
  250. # Note: In 2.3 the possibility for compiling without cyclic gc was
  251. # removed, and that in turn allows the trashcan mechanism to work
  252. # via much simpler means (e.g., it never abuses the type pointer or
  253. # refcount fields anymore). Since it's much less likely to cause a
  254. # problem now, the various constants in this expensive (we force a lot
  255. # of full collections) test are cut back from the 2.2 version.
  256. gc.enable()
  257. N = 150
  258. for count in range(2):
  259. t = []
  260. for i in range(N):
  261. t = [t, Ouch()]
  262. u = []
  263. for i in range(N):
  264. u = [u, Ouch()]
  265. v = {}
  266. for i in range(N):
  267. v = {1: v, 2: Ouch()}
  268. gc.disable()
  269. @unittest.skipUnless(threading, "test meaningless on builds without threads")
  270. def test_trashcan_threads(self):
  271. # Issue #13992: trashcan mechanism should be thread-safe
  272. NESTING = 60
  273. N_THREADS = 2
  274. def sleeper_gen():
  275. """A generator that releases the GIL when closed or dealloc'ed."""
  276. try:
  277. yield
  278. finally:
  279. time.sleep(0.000001)
  280. class C(list):
  281. # Appending to a list is atomic, which avoids the use of a lock.
  282. inits = []
  283. dels = []
  284. def __init__(self, alist):
  285. self[:] = alist
  286. C.inits.append(None)
  287. def __del__(self):
  288. # This __del__ is called by subtype_dealloc().
  289. C.dels.append(None)
  290. # `g` will release the GIL when garbage-collected. This
  291. # helps assert subtype_dealloc's behaviour when threads
  292. # switch in the middle of it.
  293. g = sleeper_gen()
  294. next(g)
  295. # Now that __del__ is finished, subtype_dealloc will proceed
  296. # to call list_dealloc, which also uses the trashcan mechanism.
  297. def make_nested():
  298. """Create a sufficiently nested container object so that the
  299. trashcan mechanism is invoked when deallocating it."""
  300. x = C([])
  301. for i in range(NESTING):
  302. x = [C([x])]
  303. del x
  304. def run_thread():
  305. """Exercise make_nested() in a loop."""
  306. while not exit:
  307. make_nested()
  308. old_checkinterval = sys.getcheckinterval()
  309. sys.setcheckinterval(3)
  310. try:
  311. exit = []
  312. threads = []
  313. for i in range(N_THREADS):
  314. t = threading.Thread(target=run_thread)
  315. threads.append(t)
  316. with start_threads(threads, lambda: exit.append(1)):
  317. time.sleep(1.0)
  318. finally:
  319. sys.setcheckinterval(old_checkinterval)
  320. gc.collect()
  321. self.assertEqual(len(C.inits), len(C.dels))
  322. def test_boom(self):
  323. class Boom:
  324. def __getattr__(self, someattribute):
  325. del self.attr
  326. raise AttributeError
  327. a = Boom()
  328. b = Boom()
  329. a.attr = b
  330. b.attr = a
  331. gc.collect()
  332. garbagelen = len(gc.garbage)
  333. del a, b
  334. # a<->b are in a trash cycle now. Collection will invoke
  335. # Boom.__getattr__ (to see whether a and b have __del__ methods), and
  336. # __getattr__ deletes the internal "attr" attributes as a side effect.
  337. # That causes the trash cycle to get reclaimed via refcounts falling to
  338. # 0, thus mutating the trash graph as a side effect of merely asking
  339. # whether __del__ exists. This used to (before 2.3b1) crash Python.
  340. # Now __getattr__ isn't called.
  341. self.assertEqual(gc.collect(), 4)
  342. self.assertEqual(len(gc.garbage), garbagelen)
  343. def test_boom2(self):
  344. class Boom2:
  345. def __init__(self):
  346. self.x = 0
  347. def __getattr__(self, someattribute):
  348. self.x += 1
  349. if self.x > 1:
  350. del self.attr
  351. raise AttributeError
  352. a = Boom2()
  353. b = Boom2()
  354. a.attr = b
  355. b.attr = a
  356. gc.collect()
  357. garbagelen = len(gc.garbage)
  358. del a, b
  359. # Much like test_boom(), except that __getattr__ doesn't break the
  360. # cycle until the second time gc checks for __del__. As of 2.3b1,
  361. # there isn't a second time, so this simply cleans up the trash cycle.
  362. # We expect a, b, a.__dict__ and b.__dict__ (4 objects) to get
  363. # reclaimed this way.
  364. self.assertEqual(gc.collect(), 4)
  365. self.assertEqual(len(gc.garbage), garbagelen)
  366. def test_boom_new(self):
  367. # boom__new and boom2_new are exactly like boom and boom2, except use
  368. # new-style classes.
  369. class Boom_New(object):
  370. def __getattr__(self, someattribute):
  371. del self.attr
  372. raise AttributeError
  373. a = Boom_New()
  374. b = Boom_New()
  375. a.attr = b
  376. b.attr = a
  377. gc.collect()
  378. garbagelen = len(gc.garbage)
  379. del a, b
  380. self.assertEqual(gc.collect(), 4)
  381. self.assertEqual(len(gc.garbage), garbagelen)
  382. def test_boom2_new(self):
  383. class Boom2_New(object):
  384. def __init__(self):
  385. self.x = 0
  386. def __getattr__(self, someattribute):
  387. self.x += 1
  388. if self.x > 1:
  389. del self.attr
  390. raise AttributeError
  391. a = Boom2_New()
  392. b = Boom2_New()
  393. a.attr = b
  394. b.attr = a
  395. gc.collect()
  396. garbagelen = len(gc.garbage)
  397. del a, b
  398. self.assertEqual(gc.collect(), 4)
  399. self.assertEqual(len(gc.garbage), garbagelen)
  400. def test_get_referents(self):
  401. alist = [1, 3, 5]
  402. got = gc.get_referents(alist)
  403. got.sort()
  404. self.assertEqual(got, alist)
  405. atuple = tuple(alist)
  406. got = gc.get_referents(atuple)
  407. got.sort()
  408. self.assertEqual(got, alist)
  409. adict = {1: 3, 5: 7}
  410. expected = [1, 3, 5, 7]
  411. got = gc.get_referents(adict)
  412. got.sort()
  413. self.assertEqual(got, expected)
  414. got = gc.get_referents([1, 2], {3: 4}, (0, 0, 0))
  415. got.sort()
  416. self.assertEqual(got, [0, 0] + range(5))
  417. self.assertEqual(gc.get_referents(1, 'a', 4j), [])
  418. def test_is_tracked(self):
  419. # Atomic built-in types are not tracked, user-defined objects and
  420. # mutable containers are.
  421. # NOTE: types with special optimizations (e.g. tuple) have tests
  422. # in their own test files instead.
  423. self.assertFalse(gc.is_tracked(None))
  424. self.assertFalse(gc.is_tracked(1))
  425. self.assertFalse(gc.is_tracked(1.0))
  426. self.assertFalse(gc.is_tracked(1.0 + 5.0j))
  427. self.assertFalse(gc.is_tracked(True))
  428. self.assertFalse(gc.is_tracked(False))
  429. self.assertFalse(gc.is_tracked("a"))
  430. self.assertFalse(gc.is_tracked(u"a"))
  431. self.assertFalse(gc.is_tracked(bytearray("a")))
  432. self.assertFalse(gc.is_tracked(type))
  433. self.assertFalse(gc.is_tracked(int))
  434. self.assertFalse(gc.is_tracked(object))
  435. self.assertFalse(gc.is_tracked(object()))
  436. class OldStyle:
  437. pass
  438. class NewStyle(object):
  439. pass
  440. self.assertTrue(gc.is_tracked(gc))
  441. self.assertTrue(gc.is_tracked(OldStyle))
  442. self.assertTrue(gc.is_tracked(OldStyle()))
  443. self.assertTrue(gc.is_tracked(NewStyle))
  444. self.assertTrue(gc.is_tracked(NewStyle()))
  445. self.assertTrue(gc.is_tracked([]))
  446. self.assertTrue(gc.is_tracked(set()))
  447. def test_bug1055820b(self):
  448. # Corresponds to temp2b.py in the bug report.
  449. ouch = []
  450. def callback(ignored):
  451. ouch[:] = [wr() for wr in WRs]
  452. Cs = [C1055820(i) for i in range(2)]
  453. WRs = [weakref.ref(c, callback) for c in Cs]
  454. c = None
  455. gc.collect()
  456. self.assertEqual(len(ouch), 0)
  457. # Make the two instances trash, and collect again. The bug was that
  458. # the callback materialized a strong reference to an instance, but gc
  459. # cleared the instance's dict anyway.
  460. Cs = None
  461. gc.collect()
  462. self.assertEqual(len(ouch), 2) # else the callbacks didn't run
  463. for x in ouch:
  464. # If the callback resurrected one of these guys, the instance
  465. # would be damaged, with an empty __dict__.
  466. self.assertEqual(x, None)
  467. class GCTogglingTests(unittest.TestCase):
  468. def setUp(self):
  469. gc.enable()
  470. def tearDown(self):
  471. gc.disable()
  472. def test_bug1055820c(self):
  473. # Corresponds to temp2c.py in the bug report. This is pretty
  474. # elaborate.
  475. c0 = C1055820(0)
  476. # Move c0 into generation 2.
  477. gc.collect()
  478. c1 = C1055820(1)
  479. c1.keep_c0_alive = c0
  480. del c0.loop # now only c1 keeps c0 alive
  481. c2 = C1055820(2)
  482. c2wr = weakref.ref(c2) # no callback!
  483. ouch = []
  484. def callback(ignored):
  485. ouch[:] = [c2wr()]
  486. # The callback gets associated with a wr on an object in generation 2.
  487. c0wr = weakref.ref(c0, callback)
  488. c0 = c1 = c2 = None
  489. # What we've set up: c0, c1, and c2 are all trash now. c0 is in
  490. # generation 2. The only thing keeping it alive is that c1 points to
  491. # it. c1 and c2 are in generation 0, and are in self-loops. There's a
  492. # global weakref to c2 (c2wr), but that weakref has no callback.
  493. # There's also a global weakref to c0 (c0wr), and that does have a
  494. # callback, and that callback references c2 via c2wr().
  495. #
  496. # c0 has a wr with callback, which references c2wr
  497. # ^
  498. # |
  499. # | Generation 2 above dots
  500. #. . . . . . . .|. . . . . . . . . . . . . . . . . . . . . . . .
  501. # | Generation 0 below dots
  502. # |
  503. # |
  504. # ^->c1 ^->c2 has a wr but no callback
  505. # | | | |
  506. # <--v <--v
  507. #
  508. # So this is the nightmare: when generation 0 gets collected, we see
  509. # that c2 has a callback-free weakref, and c1 doesn't even have a
  510. # weakref. Collecting generation 0 doesn't see c0 at all, and c0 is
  511. # the only object that has a weakref with a callback. gc clears c1
  512. # and c2. Clearing c1 has the side effect of dropping the refcount on
  513. # c0 to 0, so c0 goes away (despite that it's in an older generation)
  514. # and c0's wr callback triggers. That in turn materializes a reference
  515. # to c2 via c2wr(), but c2 gets cleared anyway by gc.
  516. # We want to let gc happen "naturally", to preserve the distinction
  517. # between generations.
  518. junk = []
  519. i = 0
  520. detector = GC_Detector()
  521. while not detector.gc_happened:
  522. i += 1
  523. if i > 10000:
  524. self.fail("gc didn't happen after 10000 iterations")
  525. self.assertEqual(len(ouch), 0)
  526. junk.append([]) # this will eventually trigger gc
  527. self.assertEqual(len(ouch), 1) # else the callback wasn't invoked
  528. for x in ouch:
  529. # If the callback resurrected c2, the instance would be damaged,
  530. # with an empty __dict__.
  531. self.assertEqual(x, None)
  532. def test_bug1055820d(self):
  533. # Corresponds to temp2d.py in the bug report. This is very much like
  534. # test_bug1055820c, but uses a __del__ method instead of a weakref
  535. # callback to sneak in a resurrection of cyclic trash.
  536. ouch = []
  537. class D(C1055820):
  538. def __del__(self):
  539. ouch[:] = [c2wr()]
  540. d0 = D(0)
  541. # Move all the above into generation 2.
  542. gc.collect()
  543. c1 = C1055820(1)
  544. c1.keep_d0_alive = d0
  545. del d0.loop # now only c1 keeps d0 alive
  546. c2 = C1055820(2)
  547. c2wr = weakref.ref(c2) # no callback!
  548. d0 = c1 = c2 = None
  549. # What we've set up: d0, c1, and c2 are all trash now. d0 is in
  550. # generation 2. The only thing keeping it alive is that c1 points to
  551. # it. c1 and c2 are in generation 0, and are in self-loops. There's
  552. # a global weakref to c2 (c2wr), but that weakref has no callback.
  553. # There are no other weakrefs.
  554. #
  555. # d0 has a __del__ method that references c2wr
  556. # ^
  557. # |
  558. # | Generation 2 above dots
  559. #. . . . . . . .|. . . . . . . . . . . . . . . . . . . . . . . .
  560. # | Generation 0 below dots
  561. # |
  562. # |
  563. # ^->c1 ^->c2 has a wr but no callback
  564. # | | | |
  565. # <--v <--v
  566. #
  567. # So this is the nightmare: when generation 0 gets collected, we see
  568. # that c2 has a callback-free weakref, and c1 doesn't even have a
  569. # weakref. Collecting generation 0 doesn't see d0 at all. gc clears
  570. # c1 and c2. Clearing c1 has the side effect of dropping the refcount
  571. # on d0 to 0, so d0 goes away (despite that it's in an older
  572. # generation) and d0's __del__ triggers. That in turn materializes
  573. # a reference to c2 via c2wr(), but c2 gets cleared anyway by gc.
  574. # We want to let gc happen "naturally", to preserve the distinction
  575. # between generations.
  576. detector = GC_Detector()
  577. junk = []
  578. i = 0
  579. while not detector.gc_happened:
  580. i += 1
  581. if i > 10000:
  582. self.fail("gc didn't happen after 10000 iterations")
  583. self.assertEqual(len(ouch), 0)
  584. junk.append([]) # this will eventually trigger gc
  585. self.assertEqual(len(ouch), 1) # else __del__ wasn't invoked
  586. for x in ouch:
  587. # If __del__ resurrected c2, the instance would be damaged, with an
  588. # empty __dict__.
  589. self.assertEqual(x, None)
  590. def test_main():
  591. enabled = gc.isenabled()
  592. gc.disable()
  593. assert not gc.isenabled()
  594. debug = gc.get_debug()
  595. gc.set_debug(debug & ~gc.DEBUG_LEAK) # this test is supposed to leak
  596. try:
  597. gc.collect() # Delete 2nd generation garbage
  598. run_unittest(GCTests, GCTogglingTests)
  599. finally:
  600. gc.set_debug(debug)
  601. # test gc.enable() even if GC is disabled by default
  602. if verbose:
  603. print "restoring automatic collection"
  604. # make sure to always test gc.enable()
  605. gc.enable()
  606. assert gc.isenabled()
  607. if not enabled:
  608. gc.disable()
  609. if __name__ == "__main__":
  610. test_main()