File tree Expand file tree Collapse file tree 2 files changed +8
-26
lines changed Expand file tree Collapse file tree 2 files changed +8
-26
lines changed Original file line number Diff line number Diff line change 16
16
from .win32 import (
17
17
create_windows_process ,
18
18
get_windows_executable_command ,
19
- terminate_windows_process ,
20
19
)
21
20
22
21
# Environment variables to inherit by default
@@ -180,13 +179,15 @@ async def stdin_writer():
180
179
finally :
181
180
# Clean up process to prevent any dangling orphaned processes
182
181
try :
183
- if sys .platform == "win32" :
184
- await terminate_windows_process (process )
185
- else :
186
- process .terminate ()
182
+ process .terminate ()
183
+ with anyio .fail_after (2.0 ):
184
+ await process .wait ()
187
185
except ProcessLookupError :
188
186
# Process already exited, which is fine
189
187
pass
188
+ except TimeoutError :
189
+ # Force kill if it doesn't terminate
190
+ process .kill ()
190
191
await read_stream .aclose ()
191
192
await write_stream .aclose ()
192
193
await read_stream_writer .aclose ()
Original file line number Diff line number Diff line change 14
14
from anyio .streams .file import FileReadStream , FileWriteStream
15
15
16
16
17
+
17
18
def get_windows_executable_command (command : str ) -> str :
18
19
"""
19
20
Get the correct executable command normalized for Windows.
@@ -158,25 +159,5 @@ async def create_windows_process(
158
159
cwd = cwd ,
159
160
bufsize = 0 ,
160
161
)
161
- return FallbackProcess (popen_obj )
162
-
163
-
164
- async def terminate_windows_process (process : Process | FallbackProcess ):
165
- """
166
- Terminate a Windows process.
167
162
168
- Note: On Windows, terminating a process with process.terminate() doesn't
169
- always guarantee immediate process termination.
170
- So we give it 2s to exit, or we call process.kill()
171
- which sends a SIGKILL equivalent signal.
172
-
173
- Args:
174
- process: The process to terminate
175
- """
176
- try :
177
- process .terminate ()
178
- with anyio .fail_after (2.0 ):
179
- await process .wait ()
180
- except TimeoutError :
181
- # Force kill if it doesn't terminate
182
- process .kill ()
163
+ return FallbackProcess (popen_obj )
You can’t perform that action at this time.
0 commit comments