File tree Expand file tree Collapse file tree 1 file changed +26
-7
lines changed
Expand file tree Collapse file tree 1 file changed +26
-7
lines changed Original file line number Diff line number Diff line change @@ -76,20 +76,39 @@ async def __aexit__(
7676 exc_tb : object | None ,
7777 ) -> None :
7878 """Terminate and wait on process exit inside a thread."""
79- self .popen .terminate ()
80- await to_thread .run_sync (self .popen .wait )
79+ try :
80+ self .popen .terminate ()
81+ await to_thread .run_sync (self .popen .wait )
82+ except Exception :
83+ pass
8184
8285 # Close the file handles to prevent ResourceWarning
86+ # Handle already-closed streams gracefully
8387 if self .stdin :
84- await self .stdin .aclose ()
88+ try :
89+ await self .stdin .aclose ()
90+ except Exception :
91+ pass # Already closed
8592 if self .stdout :
86- await self .stdout .aclose ()
93+ try :
94+ await self .stdout .aclose ()
95+ except Exception :
96+ pass # Already closed
8797 if self .stdin_raw :
88- self .stdin_raw .close ()
98+ try :
99+ self .stdin_raw .close ()
100+ except Exception :
101+ pass # Already closed
89102 if self .stdout_raw :
90- self .stdout_raw .close ()
103+ try :
104+ self .stdout_raw .close ()
105+ except Exception :
106+ pass # Already closed
91107 if self .stderr :
92- self .stderr .close ()
108+ try :
109+ self .stderr .close ()
110+ except Exception :
111+ pass # Already closed
93112
94113 async def wait (self ):
95114 """Async wait for process completion."""
You can’t perform that action at this time.
0 commit comments