@@ -343,19 +343,39 @@ def test_finalize_structseq(self):
343
343
out , err = self .run_embedded_interpreter ("test_repeated_init_exec" , code )
344
344
self .assertEqual (out , 'Tests passed\n ' * INIT_LOOPS )
345
345
346
- @support .skip_if_pgo_task
347
346
def test_quickened_static_code_gets_unquickened_at_Py_FINALIZE (self ):
348
347
# https://github.com/python/cpython/issues/92031
349
- code = """if 1:
350
- from importlib._bootstrap import _handle_fromlist
351
- import dis
352
- for name in dis.opmap:
353
- # quicken this frozen code object.
354
- _handle_fromlist(dis, [name], lambda *args: None)
355
- """
348
+
349
+ # Do these imports outside of the code string to avoid using
350
+ # importlib too much from within the code string, so that
351
+ # _handle_fromlist doesn't get quickened until we intend it to.
352
+ from dis import _all_opmap
353
+ resume = _all_opmap ["RESUME" ]
354
+ resume_quick = _all_opmap ["RESUME_QUICK" ]
355
+ from test .test_dis import QUICKENING_WARMUP_DELAY
356
+
357
+ code = textwrap .dedent (f"""\
358
+ import importlib._bootstrap
359
+ func = importlib._bootstrap._handle_fromlist
360
+ code = func.__code__
361
+
362
+ # Assert initially unquickened.
363
+ # Use sets to account for byte order.
364
+ if set(code._co_code_adaptive[:2]) != set([{ resume } , 0]):
365
+ raise AssertionError()
366
+
367
+ for i in range({ QUICKENING_WARMUP_DELAY } ):
368
+ func(importlib._bootstrap, ["x"], lambda *args: None)
369
+
370
+ # Assert quickening worked
371
+ if set(code._co_code_adaptive[:2]) != set([{ resume_quick } , 0]):
372
+ raise AssertionError()
373
+
374
+ print("Tests passed")
375
+ """ )
356
376
run = self .run_embedded_interpreter
357
- for i in range ( 50 ):
358
- out , err = run ( "test_repeated_init_exec" , code , timeout = 60 )
377
+ out , err = run ( "test_repeated_init_exec" , code )
378
+ self . assertEqual ( out , 'Tests passed \n ' * INIT_LOOPS )
359
379
360
380
def test_ucnhash_capi_reset (self ):
361
381
# bpo-47182: unicodeobject.c:ucnhash_capi was not reset on shutdown.
0 commit comments