Run ngspice as a direct child process so it can be reliably terminated. :param args: ngspice command and arguments as a list (run without a shell, so the timeout kills ngspice itself, not just a shell wrapper). :param stdout_path: file to receive ngspice console output, or
(args, stdout_path=None, timeout=None)
| 302 | return output |
| 303 | |
| 304 | def _run_ngspice(args, stdout_path=None, timeout=None): |
| 305 | """Run ngspice as a direct child process so it can be reliably terminated. |
| 306 | |
| 307 | :param args: ngspice command and arguments as a list (run without a shell, |
| 308 | so the timeout kills ngspice itself, not just a shell wrapper). |
| 309 | :param stdout_path: file to receive ngspice console output, or None to inherit. |
| 310 | :param timeout: seconds before the job is killed, or None for no limit |
| 311 | (default; identical to the previous os.system behaviour). |
| 312 | :return: True if ngspice completed, False if it timed out or could not run. |
| 313 | """ |
| 314 | out = open(stdout_path, 'w') if stdout_path is not None else None |
| 315 | try: |
| 316 | subprocess.run(args, stdout=out, timeout=timeout) |
| 317 | return True |
| 318 | except subprocess.TimeoutExpired: |
| 319 | print("ERROR: NGspice exceeded the {} s time limit and was terminated.".format(timeout)) |
| 320 | return False |
| 321 | except FileNotFoundError: |
| 322 | print("ERROR: NGspice cannot be executed with: '{}'.".format(ini.ngspice)) |
| 323 | return False |
| 324 | finally: |
| 325 | if out is not None: |
| 326 | out.close() |
| 327 | |
| 328 | |
| 329 | def ngspice2traces(cirFile, simCmd, namesDict, stepCmd=None, parList=None, |
no test coverage detected