Close a `proc` process opened pipes and kill the process.
(proc)
| 182 | |
| 183 | |
| 184 | def 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 | |
| 215 | def load_shared_library(dll_loc, *args): |