class Killer:
def __init__(self):
self.CHROME_PID = []
self.CHROME_LIV = []
def get_chrome_pid(self, live=False):
try:
for proc in psutil.process_iter(attrs=['pid', 'name']):
if 'undetected_chromedriver' in proc.info['name'].lower() or 'chrome' in proc.info['name'].lower():
if live:
if proc.info['pid'] not in self.CHROME_LIV:
self.CHROME_LIV.append(proc.info['pid'])
else:
if proc.info['pid'] not in self.CHROME_LIV:
self.CHROME_PID.append(proc.info['pid'])
except Exception as e:
print(f'Error getting Chrome PID: {e}')
def kill(self):
try:
for pid in self.CHROME_PID:
if check_chrome(pid):
if not kill_chrome(pid):
print(f'KILL chrome error {pid}')
except Exception as e:
config.log.warning(f'kill | {e}')
def kill_chrome(pid) -> bool:
global result
try:
if sys.platform != 'win32':
result = subprocess.run(["ps", "-p", str(pid), "-o", "comm="], stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
process_name = result.stdout.decode("utf-8").strip().lower()
if process_name == "undetected_chromedriver" or process_name == "chrome":
subprocess.run(["kill", str(pid)])
return True
else:
config.log.warning(f"Процесс с PID {pid} не является Chrome. Имя процесса: {process_name}")
return False
else:
result = subprocess.run(["tasklist"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
process_lines = result.stdout.decode("cp1251").strip().split("\n")
for line in process_lines[1:]:
process_info = line.split()[1]
process_name = line.split()[0].lower()
if process_name == "undetected_chromedriver.e" or process_name == "chrome.exe" and int(
process_info) == pid:
subprocess.run(["taskkill", "/F", "/PID", str(pid)])
return True
config.log.warning(f"Процесс с PID {pid} не является Chrome.")
return False
except subprocess.CalledProcessError as e:
config.log.warning(f"Ошибка при выполнении kill_chrome | {e}\n{result}")
return False
except FileNotFoundError:
config.log.warning(f"Команда 'kill' не поддерживается в данной системе {result}")
return False
def check_chrome(pid) -> bool:
global result
try:
if sys.platform != 'win32':
result = subprocess.run(["ps", "-p", str(pid), "-o", "comm="], stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
process_name = result.stdout.decode("utf-8").strip().lower()
if process_name == "undetected_chromedriver" or process_name == "chrome":
return True
else:
return False
else:
result = subprocess.run(["tasklist"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
process_lines = result.stdout.decode("cp1251").strip().split("\n")
for line in process_lines[1:]:
process_info = line.split()[1]
process_name = line.split()[0].lower()
if process_name == "undetected_chromedriver.e" or process_name == "chrome.exe" and int(
process_info) == pid:
return True
return False
except subprocess.CalledProcessError as e:
return False
except FileNotFoundError:
return False
Исправил процедуру, добавив CHARSET utf8mb4:
PROCEDURE `InsertNewMessage`(
IN `in_from_userid` BIGINT,
IN `in_message_id` INT(11),
IN `in_user_select_lang` VARCHAR(2),
IN `in_lang_detect` VARCHAR(2),
IN `in_voice_text` TEXT CHARSET utf8mb4,
IN `in_voice_translate` TEXT CHARSET utf8mb4,
IN `in_voice_file` MEDIUMBLOB
)
ERROR:root:classes.psql InsertNewMessage data=(123, 321, 'ab', 'bc', 'txt', 'тест'...(1366, "Incorrect string value: '\\xD1\\x83\...' for column ``.``.`in_voice_translate` at row 0")
"Открыть" папку username\папка так: