77from test .support import os_helper
88
99from .setup import setup_process , setup_test_dir
10- from .runtests import RunTests , JsonFileType
10+ from .runtests import RunTests , JsonFile
1111from .single import run_single_test
1212from .utils import (
1313 StrPath , StrJSON , FilterTuple , MS_WINDOWS ,
@@ -57,28 +57,10 @@ def create_worker_process(runtests: RunTests, output_fd: int,
5757
5858 # Pass json_file to the worker process
5959 json_file = runtests .json_file
60- if isinstance (json_file , str ):
61- # Filename: nothing to do to
62- pass
63- elif MS_WINDOWS :
64- # Windows handle
65- startupinfo = subprocess .STARTUPINFO ()
66- startupinfo .lpAttributeList = {"handle_list" : [json_file ]}
67- kwargs ['startupinfo' ] = startupinfo
68- else :
69- # Unix file descriptor
70- kwargs ['pass_fds' ] = [json_file ]
71-
72- if USE_PROCESS_GROUP :
73- kwargs ['start_new_session' ] = True
60+ json_file .configure_subprocess (kwargs )
7461
75- if MS_WINDOWS :
76- os .set_handle_inheritable (json_file , True )
77- try :
62+ with json_file .inherit_subprocess ():
7863 return subprocess .Popen (cmd , ** kwargs )
79- finally :
80- if MS_WINDOWS :
81- os .set_handle_inheritable (json_file , False )
8264
8365
8466def worker_process (worker_json : StrJSON ) -> NoReturn :
@@ -89,13 +71,7 @@ def worker_process(worker_json: StrJSON) -> NoReturn:
8971 # - Unix: file descriptor (int)
9072 # - Windows: handle (int)
9173 # - Emscripten/WASI or if --python is used: filename (str)
92- json_file : JsonFileType = runtests .json_file
93-
94- if MS_WINDOWS :
95- import msvcrt
96- # Create a file descriptor from the handle
97- json_file = msvcrt .open_osfhandle (json_file , os .O_WRONLY )
98-
74+ json_file : JsonFile = runtests .json_file
9975
10076 setup_test_dir (runtests .test_dir )
10177 setup_process ()
@@ -109,7 +85,7 @@ def worker_process(worker_json: StrJSON) -> NoReturn:
10985
11086 result = run_single_test (test_name , runtests )
11187
112- with open (json_file , 'w' , encoding = 'utf-8' ) as json_fp :
88+ with json_file . open ('w' , encoding = 'utf-8' ) as json_fp :
11389 result .write_json_into (json_fp )
11490
11591 sys .exit (0 )
0 commit comments