MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / close

Function close

src/commoncode/command.py:184–212  ·  view source on GitHub ↗

Close a `proc` process opened pipes and kill the process.

(proc)

Source from the content-addressed store, hash-verified

182
183
184def close(proc):
185 """
186 Close a `proc` process opened pipes and kill the process.
187 """
188 if not proc:
189 return
190
191 def close_pipe(p):
192 if not p:
193 return
194 try:
195 p.close()
196 except IOError:
197 pass
198
199 close_pipe(getattr(proc, "stdin", None))
200 close_pipe(getattr(proc, "stdout", None))
201 close_pipe(getattr(proc, "stderr", None))
202
203 try:
204 # Ensure process death otherwise proc.wait may hang in some cases
205 # NB: this will run only on POSIX OSes supporting signals
206 os.kill(proc.pid, signal.SIGKILL) # NOQA
207 except Exception:
208 pass
209
210 # This may slow things down a tad on non-POSIX Oses but is safe:
211 # this calls os.waitpid() to make sure the process is dead
212 proc.wait()
213
214
215def load_shared_library(dll_loc, *args):

Callers 5

executeFunction · 0.70
~izstreamMethod · 0.50
openMethod · 0.50
~ozstreamMethod · 0.50
openMethod · 0.50

Calls 2

close_pipeFunction · 0.85
waitMethod · 0.80

Tested by

no test coverage detected