mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-19 01:45:27 +00:00
feat: 优化代码结构,receptor开关,修改为 tcp 通信 (#13078)
* feat: 优化代码结构,receptor开关,修改为 tcp 通信 * fix: 修改导包路径 * fix: 修复错别字 * fix: 修改导包路径 * perf: 优化代码 * fix: 修复任务不执行的问题 * perf: 优化配置项名称 * perf: 优化代码结构 * perf: 优化代码 --------- Co-authored-by: Aaron3S <chenyang@fit2cloud.com>
This commit is contained in:
0
apps/libs/process/__init__.py
Normal file
0
apps/libs/process/__init__.py
Normal file
26
apps/libs/process/ssh.py
Normal file
26
apps/libs/process/ssh.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import logging
|
||||
|
||||
import psutil
|
||||
from psutil import NoSuchProcess
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _should_kill(process):
|
||||
return process.pid != 1 and process.name() == 'ssh'
|
||||
|
||||
|
||||
def kill_ansible_ssh_process(pid):
|
||||
try:
|
||||
process = psutil.Process(pid)
|
||||
except NoSuchProcess as e:
|
||||
logger.error(f"No such process: {e}")
|
||||
return
|
||||
|
||||
for child in process.children(recursive=True):
|
||||
if not _should_kill(child):
|
||||
return
|
||||
try:
|
||||
child.kill()
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to kill process {child.pid}: {e}")
|
Reference in New Issue
Block a user