fix bug
This commit is contained in:
@@ -115,7 +115,7 @@ class OccupationResolver:
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["sudo", "lsof", device_path],
|
||||
capture_output=True, text=True, timeout=10
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8', timeout=10
|
||||
)
|
||||
if result.returncode == 0 and result.stdout.strip():
|
||||
logger.info(f"设备 {device_path} 被以下进程占用:\n{result.stdout}")
|
||||
@@ -127,7 +127,7 @@ class OccupationResolver:
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["sudo", "fuser", device_path],
|
||||
capture_output=True, text=True, timeout=10
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8', timeout=10
|
||||
)
|
||||
if result.returncode == 0 and result.stdout.strip():
|
||||
logger.info(f"设备 {device_path} 被以下进程占用: {result.stdout.strip()}")
|
||||
@@ -149,7 +149,7 @@ class OccupationResolver:
|
||||
# 使用 fuser -k 终止进程
|
||||
result = subprocess.run(
|
||||
["sudo", "fuser", "-k", device_path],
|
||||
capture_output=True, text=True, timeout=10
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8', timeout=10
|
||||
)
|
||||
|
||||
if result.returncode == 0 or result.returncode == 1: # 1 表示没有进程被终止
|
||||
|
||||
Reference in New Issue
Block a user