11import atexit
22import os
33import subprocess
4- import sys
54import tempfile
65import textwrap
76import unittest
@@ -195,7 +194,6 @@ def callback():
195194 # Python built with Py_TRACE_REFS fail with a fatal error in
196195 # _PyRefchain_Trace() on memory allocation error.
197196 @unittest .skipIf (support .Py_TRACE_REFS , 'cannot test Py_TRACE_REFS build' )
198- @support .requires_subprocess ()
199197 def test_atexit_with_low_memory (self ):
200198 # gh-140080: Test that setting low memory after registering an atexit
201199 # callback doesn't cause an infinite loop during finalization.
@@ -217,17 +215,17 @@ def callback():
217215
218216 try :
219217 with SuppressCrashReport ():
220- proc = subprocess . run (
221- [ sys . executable , script ],
222- capture_output = True ,
223- timeout = 10
224- )
218+ with script_helper . spawn_python ( script ,
219+ stderr = subprocess . PIPE ) as proc :
220+ proc . wait ()
221+ stdout = proc . stdout . read ()
222+ stderr = proc . stderr . read ( )
225223 finally :
226224 os .unlink (script )
227225
228226 self .assertIn (proc .returncode , (0 , 1 ))
229- self .assertNotIn (b"hello" , proc . stdout )
230- self .assertIn (b"MemoryError" , proc . stderr )
227+ self .assertNotIn (b"hello" , stdout )
228+ self .assertIn (b"MemoryError" , stderr )
231229
232230
233231if __name__ == "__main__" :
0 commit comments