@@ -68,6 +68,17 @@ def run():
6868
6969class TestBase (unittest .TestCase ):
7070
71+ def pipe (self ):
72+ def ensure_closed (fd ):
73+ try :
74+ os .close (fd )
75+ except OSError :
76+ pass
77+ r , w = os .pipe ()
78+ self .addCleanup (lambda : ensure_closed (r ))
79+ self .addCleanup (lambda : ensure_closed (w ))
80+ return r , w
81+
7182 def tearDown (self ):
7283 clean_up_interpreters ()
7384
@@ -262,7 +273,7 @@ def test_subinterpreter(self):
262273 self .assertFalse (interp .is_running ())
263274
264275 def test_finished (self ):
265- r , w = os .pipe ()
276+ r , w = self .pipe ()
266277 interp = interpreters .create ()
267278 interp .run (f"""if True:
268279 import os
@@ -299,8 +310,8 @@ def test_bad_id(self):
299310 interp .is_running ()
300311
301312 def test_with_only_background_threads (self ):
302- r_interp , w_interp = os .pipe ()
303- r_thread , w_thread = os .pipe ()
313+ r_interp , w_interp = self .pipe ()
314+ r_thread , w_thread = self .pipe ()
304315
305316 DONE = b'D'
306317 FINISHED = b'F'
@@ -425,8 +436,8 @@ def test_still_running(self):
425436 self .assertTrue (interp .is_running ())
426437
427438 def test_subthreads_still_running (self ):
428- r_interp , w_interp = os .pipe ()
429- r_thread , w_thread = os .pipe ()
439+ r_interp , w_interp = self .pipe ()
440+ r_thread , w_thread = self .pipe ()
430441
431442 FINISHED = b'F'
432443
@@ -532,8 +543,8 @@ def test_bytes_for_script(self):
532543 interp .run (b'print("spam")' )
533544
534545 def test_with_background_threads_still_running (self ):
535- r_interp , w_interp = os .pipe ()
536- r_thread , w_thread = os .pipe ()
546+ r_interp , w_interp = self .pipe ()
547+ r_thread , w_thread = self .pipe ()
537548
538549 RAN = b'R'
539550 DONE = b'D'
0 commit comments