| | 158 | pid = int(pf.read().strip()) |
| | 159 | pf.close() |
| | 160 | |
| | 161 | if os.name == 'nt': |
| | 162 | try: |
| | 163 | from ctypes import (windll, c_ulong, c_int, Structure, c_char, POINTER, pointer, ) |
| | 164 | except: |
| | 165 | return True |
| | 166 | |
| | 167 | class PROCESSENTRY32(Structure): |
| | 168 | _fields_ = [ |
| | 169 | ('dwSize', c_ulong, ), |
| | 170 | ('cntUsage', c_ulong, ), |
| | 171 | ('th32ProcessID', c_ulong, ), |
| | 172 | ('th32DefaultHeapID', c_ulong, ), |
| | 173 | ('th32ModuleID', c_ulong, ), |
| | 174 | ('cntThreads', c_ulong, ), |
| | 175 | ('th32ParentProcessID', c_ulong, ), |
| | 176 | ('pcPriClassBase', c_ulong, ), |
| | 177 | ('dwFlags', c_ulong, ), |
| | 178 | ('szExeFile', c_char*512, ), |
| | 179 | ] |
| | 180 | def __init__(self): |
| | 181 | Structure.__init__(self, 512+9*4) |
| | 182 | |
| | 183 | k = windll.kernel32 |
| | 184 | k.CreateToolhelp32Snapshot.argtypes = c_ulong, c_ulong, |
| | 185 | k.CreateToolhelp32Snapshot.restype = c_int |
| | 186 | k.Process32First.argtypes = c_int, POINTER(PROCESSENTRY32), |
| | 187 | k.Process32First.restype = c_int |
| | 188 | k.Process32Next.argtypes = c_int, POINTER(PROCESSENTRY32), |
| | 189 | k.Process32Next.restype = c_int |
| | 190 | |
| | 191 | def get_p(p): |
| | 192 | h = k.CreateToolhelp32Snapshot(2, 0) # TH32CS_SNAPPROCESS |
| | 193 | assert h > 0, 'CreateToolhelp32Snapshot failed' |
| | 194 | b = pointer(PROCESSENTRY32()) |
| | 195 | f = k.Process32First(h, b) |
| | 196 | while f: |
| | 197 | if b.contents.th32ProcessID == p: |
| | 198 | return b.contents.szExeFile |
| | 199 | f = k.Process32Next(h, b) |
| | 200 | |
| | 201 | if get_p(pid) == 'python.exe': |
| | 202 | return True |
| | 203 | return False |