diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d2b7ed..0ba0b4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### 0.0.7 (2024-06-19) +1. add `utils.is_running_linux`, `utils.is_running_win32` + + ### 0.0.6 (2024-06-19) 1. add `utils.xor_encode_decode` 2. add `utils.is_running`, `utils.lock_pid_file` diff --git a/morebuiltins/__init__.py b/morebuiltins/__init__.py index 1d8ee55..56c0d8a 100644 --- a/morebuiltins/__init__.py +++ b/morebuiltins/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.0.6" +__version__ = "0.0.7" __all__ = [ "morebuiltins.utils", "morebuiltins.functools", diff --git a/morebuiltins/utils.py b/morebuiltins/utils.py index 134c54b..8c4188e 100644 --- a/morebuiltins/utils.py +++ b/morebuiltins/utils.py @@ -887,6 +887,23 @@ def xor_encode_decode(data, key): return bytes([b ^ k for b, k in zip(data, extended_key)]) +def is_running_win32(pid: int): + with os.popen('tasklist /fo csv /fi "pid eq %s"' % int(pid)) as f: + f.readline() + text = f.readline() + return bool(text) + + +def is_running_linux(pid: int): + try: + os.kill(int(pid), 0) + return True + except OSError: + return False + except SystemError: + return True + + def is_running(pid): """Check if the given process ID is running. @@ -910,19 +927,9 @@ def is_running(pid): except ValueError: return False if sys.platform == "win32": - with os.popen('tasklist /fo csv /fi "pid eq %s"' % int(pid)) as f: - f.readline() - text = f.readline() - return bool(text) + return is_running_win32(pid) else: - try: - os.kill(int(pid), 0) - return True - except OSError: - return False - except SystemError: - # maybe windows? - return True + return is_running_linux(pid) def set_pid_file(