Vérifiez si PID existe sous Windows avec Python sans nécessiter de bibliothèques

Est-il possible de vérifier si un PID existe sous Windows avec Python sans avoir besoin de bibliothèques? Comment?

Ceci est résolu avec une petite tasse de WINAPI.

 def pid_running(pid): import ctypes kernel32 = ctypes.windll.kernel32 SYNCHRONIZE = 0x100000 process = kernel32.OpenProcess(SYNCHRONIZE, 0, pid) if process != 0: kernel32.CloseHandle(process) return True else: return False 

Cela fonctionne sur mon système ..

 >>> import subprocess >>> out = subprocess.check_output(["tasklist","/fi","PID eq 1234"]).ssortingp() >>> if out == "INFO: No tasks are running which match the specified criteria.": ... print "No such PID :D" ... No such PID :D