From d1365d77bf5d84f379a9dcfe2b97aed1e0232bde 2014-08-20 17:29:11 From: Min RK Date: 2014-08-20 17:29:11 Subject: [PATCH] Merge pull request #6338 from aminb/cli-check_pid Add .NET implementation of check_pid --- diff --git a/IPython/utils/_process_cli.py b/IPython/utils/_process_cli.py index eb69d3f..a7b7b90 100644 --- a/IPython/utils/_process_cli.py +++ b/IPython/utils/_process_cli.py @@ -61,3 +61,18 @@ def getoutput(cmd): myError = reg.StandardError error = myError.ReadToEnd() return output + +def check_pid(pid): + """ + Check if a process with the given PID (pid) exists + """ + try: + System.Diagnostics.Process.GetProcessById(pid) + # process with given pid is running + return True + except System.InvalidOperationException: + # process wasn't started by this object (but is running) + return True + except System.ArgumentException: + # process with given pid isn't running + return False diff --git a/IPython/utils/process.py b/IPython/utils/process.py index 2a19945..64b7254 100644 --- a/IPython/utils/process.py +++ b/IPython/utils/process.py @@ -23,7 +23,7 @@ import sys if sys.platform == 'win32': from ._process_win32 import _find_cmd, system, getoutput, arg_split, check_pid elif sys.platform == 'cli': - from ._process_cli import _find_cmd, system, getoutput, arg_split + from ._process_cli import _find_cmd, system, getoutput, arg_split, check_pid else: from ._process_posix import _find_cmd, system, getoutput, arg_split, check_pid