1
1
from test .support import (gc_collect , bigmemtest , _2G ,
2
2
cpython_only , captured_stdout ,
3
- check_disallow_instantiation , is_emscripten , is_wasi )
3
+ check_disallow_instantiation , is_emscripten , is_wasi ,
4
+ SHORT_TIMEOUT )
5
+ import multiprocessing
4
6
import locale
5
7
import re
6
8
import string
@@ -2408,7 +2410,6 @@ def test_template_function_and_flag_is_deprecated(self):
2408
2410
self .assertFalse (template_re1 .match ('nope' ))
2409
2411
2410
2412
def test_regression_gh94675 (self ):
2411
- start = time .perf_counter ()
2412
2413
pattern = re .compile (r'(?<=[({}])(((//[^\n]*)?[\n])([\000-\040])*)*'
2413
2414
r'((/[^/\[\n]*(([^\n]|(\[\n]*(]*)*\]))'
2414
2415
r'[^/\[]*)*/))((((//[^\n]*)?[\n])'
@@ -2417,10 +2418,15 @@ def test_regression_gh94675(self):
2417
2418
input_js = '''a(function() {
2418
2419
///////////////////////////////////////////////////////////////////
2419
2420
});'''
2420
- _ = pattern .sub ('' , input_js )
2421
- t = time .perf_counter () - start
2422
- # Without optimization it takes 0.017 second on my computer.
2423
- self .assertLess (t , 0.5 )
2421
+ p = multiprocessing .Process (target = pattern .sub , args = ('' , input_js ))
2422
+ p .start ()
2423
+ p .join (SHORT_TIMEOUT )
2424
+ try :
2425
+ self .assertFalse (p .is_alive (), 'pattern.sub() timed out' )
2426
+ finally :
2427
+ if p .is_alive ():
2428
+ p .terminate ()
2429
+ p .join ()
2424
2430
2425
2431
2426
2432
def get_debug_out (pat ):
0 commit comments