-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for dmypy on Windows (#5859)
This also adds an IPC module to abstract communication between the client and server for Unix and Windows. Closes #5019
- Loading branch information
1 parent
b790539
commit f010360
Showing
9 changed files
with
491 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import sys | ||
|
||
from typing import Any, Callable | ||
|
||
if sys.platform == 'win32': | ||
import ctypes | ||
from ctypes.wintypes import DWORD, HANDLE | ||
import subprocess | ||
|
||
PROCESS_QUERY_LIMITED_INFORMATION = ctypes.c_ulong(0x1000) | ||
|
||
kernel32 = ctypes.windll.kernel32 | ||
OpenProcess = kernel32.OpenProcess # type: Callable[[DWORD, int, int], HANDLE] | ||
GetExitCodeProcess = kernel32.GetExitCodeProcess # type: Callable[[HANDLE, Any], int] | ||
else: | ||
import os | ||
import signal | ||
|
||
|
||
def alive(pid: int) -> bool: | ||
"""Is the process alive?""" | ||
if sys.platform == 'win32': | ||
# why can't anything be easy... | ||
status = DWORD() | ||
handle = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, | ||
0, | ||
pid) | ||
GetExitCodeProcess(handle, ctypes.byref(status)) | ||
return status.value == 259 # STILL_ACTIVE | ||
else: | ||
try: | ||
os.kill(pid, 0) | ||
except OSError: | ||
return False | ||
return True | ||
|
||
|
||
def kill(pid: int) -> None: | ||
"""Kill the process.""" | ||
if sys.platform == 'win32': | ||
subprocess.check_output("taskkill /pid {pid} /f /t".format(pid=pid)) | ||
else: | ||
os.kill(pid, signal.SIGKILL) |
Oops, something went wrong.