Skip to content

Commit 42f90ab

Browse files
committed
fix: use spawn_python
Signed-off-by: yihong0618 <[email protected]>
1 parent 5e288a2 commit 42f90ab

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

Lib/test/test_atexit.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import atexit
22
import os
33
import subprocess
4-
import sys
54
import tempfile
65
import textwrap
76
import 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

233231
if __name__ == "__main__":

0 commit comments

Comments
 (0)