MCPcopy Create free account
hub / github.com/mysql/mysql-connector-python / process_running

Function process_running

mysqlx-connector-python/tests/mysqld.py:81–107  ·  view source on GitHub ↗

Check whether a process is running This function takes the process ID or pid and checks whether it is running. It works for Windows and UNIX-like systems. Return True or False

(pid)

Source from the content-addressed store, hash-verified

79
80
81def process_running(pid):
82 """Check whether a process is running
83
84 This function takes the process ID or pid and checks whether it is
85 running. It works for Windows and UNIX-like systems.
86
87 Return True or False
88 """
89 if os.name == "nt":
90 # We are on Windows
91 process = subprocess.Popen(["tasklist"], stdout=subprocess.PIPE)
92 output, _ = process.communicate()
93 lines = [line.split(None, 2) for line in output.splitlines() if line]
94 for name, apid, _ in lines:
95 name = name.decode("utf-8")
96 if name == EXEC_MYSQLD and pid == int(apid):
97 LOGGER.debug("Process %d is running.", pid)
98 return True
99 LOGGER.debug("Process %d not running.", pid)
100 return False
101
102 # We are on a UNIX-like system
103 try:
104 os.kill(pid, 0)
105 except OSError:
106 return False
107 return True
108
109
110def process_terminate(pid):

Callers 1

check_runningMethod · 0.70

Calls 1

killMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…