|
35 | 35 | from __future__ import print_function, absolute_import, division |
36 | 36 | import sys |
37 | 37 | import stackless |
38 | | -import codecs |
| 38 | +import builtins |
39 | 39 | import os |
40 | 40 | import time |
41 | 41 | import collections |
@@ -220,13 +220,14 @@ def __init__(self, out, checks, tasklets): |
220 | 220 | self.checks = checks |
221 | 221 | self.tasklets = tasklets |
222 | 222 |
|
223 | | - # register the detector in the codecs search path |
224 | | - # it will be cleared after clearing the thread states |
225 | | - # this way the detector runs very late |
226 | | - def dummy_codecs_search_function(name): |
227 | | - return None |
228 | | - codecs.register(dummy_codecs_search_function) |
229 | | - dummy_codecs_search_function.x = self |
| 223 | + # In Py_Finalize() the PyImport_Cleanup() runs shortly after |
| 224 | + # slp_kill_tasks_with_stacks(NULL). |
| 225 | + # As very first action of PyImport_Cleanup() the Python |
| 226 | + # interpreter sets builtins._ to None. |
| 227 | + # Therefore we can use this assignment to trigger the execution |
| 228 | + # of this detector. At this point the interpreter is still almost fully |
| 229 | + # intact. |
| 230 | + builtins._ = self |
230 | 231 |
|
231 | 232 | def __del__(self): |
232 | 233 | if self.debug: |
@@ -405,7 +406,7 @@ def interpreter_shutdown_test(): |
405 | 406 | test = Test() |
406 | 407 | detector = Detector(test.out, test.checks, test.tasklets) |
407 | 408 | assert sys.getrefcount(detector) - sys.getrefcount(object()) == 2 |
408 | | - detector = None # the last ref is now in the codecs search path |
| 409 | + detector = None # the last ref is now in bultins._ |
409 | 410 | thread.start_new_thread(test.other_thread_main, ()) |
410 | 411 | ready.acquire() # Be sure the other thread is ready. |
411 | 412 | # print("at end") |
|
0 commit comments