@@ -68,6 +68,17 @@ def run():
68
68
69
69
class TestBase (unittest .TestCase ):
70
70
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
+
71
82
def tearDown (self ):
72
83
clean_up_interpreters ()
73
84
@@ -262,7 +273,7 @@ def test_subinterpreter(self):
262
273
self .assertFalse (interp .is_running ())
263
274
264
275
def test_finished (self ):
265
- r , w = os .pipe ()
276
+ r , w = self .pipe ()
266
277
interp = interpreters .create ()
267
278
interp .run (f"""if True:
268
279
import os
@@ -299,8 +310,8 @@ def test_bad_id(self):
299
310
interp .is_running ()
300
311
301
312
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 ()
304
315
305
316
DONE = b'D'
306
317
FINISHED = b'F'
@@ -425,8 +436,8 @@ def test_still_running(self):
425
436
self .assertTrue (interp .is_running ())
426
437
427
438
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 ()
430
441
431
442
FINISHED = b'F'
432
443
@@ -532,8 +543,8 @@ def test_bytes_for_script(self):
532
543
interp .run (b'print("spam")' )
533
544
534
545
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 ()
537
548
538
549
RAN = b'R'
539
550
DONE = b'D'
0 commit comments