MCPcopy Create free account
hub / github.com/CJackHwang/AIstudioProxyAPI / kill_process_interactive

Function kill_process_interactive

launch_camoufox.py:517–590  ·  view source on GitHub ↗
(pid: int)

Source from the content-addressed store, hash-verified

515
516
517def kill_process_interactive(pid: int) -> bool:
518 system_platform = platform.system()
519 success = False
520 logger.info(f" Attempting to terminate process PID: {pid}...")
521 try:
522 if system_platform == "Linux" or system_platform == "Darwin":
523 result_term = subprocess.run(
524 f"kill {pid}",
525 shell=True,
526 capture_output=True,
527 text=True,
528 timeout=3,
529 check=False,
530 )
531 if result_term.returncode == 0:
532 logger.info(f" ✓ PID {pid} sent SIGTERM signal.")
533 success = True
534 else:
535 logger.warning(
536 f" PID {pid} SIGTERM failed: {result_term.stderr.strip() or result_term.stdout.strip()}. Attempting SIGKILL..."
537 )
538 result_kill = subprocess.run(
539 f"kill -9 {pid}",
540 shell=True,
541 capture_output=True,
542 text=True,
543 timeout=3,
544 check=False,
545 )
546 if result_kill.returncode == 0:
547 logger.info(f" ✓ PID {pid} sent SIGKILL signal.")
548 success = True
549 else:
550 logger.error(
551 f" ✗ PID {pid} SIGKILL failed: {result_kill.stderr.strip() or result_kill.stdout.strip()}."
552 )
553 elif system_platform == "Windows":
554 command_desc = f"taskkill /PID {pid} /T /F"
555 result = subprocess.run(
556 command_desc,
557 shell=True,
558 capture_output=True,
559 text=True,
560 timeout=5,
561 check=False,
562 )
563 output = result.stdout.strip()
564 error_output = result.stderr.strip()
565 # Check for localized "Success" messages (e.g., "成功" for Chinese systems)
566 if result.returncode == 0 and (
567 "SUCCESS" in output.upper() or "成功" in output
568 ):
569 logger.info(f" ✓ PID {pid} terminated via taskkill /F.")
570 success = True
571 # Check for localized "Not Found" messages (e.g., "找不到" for Chinese systems)
572 elif (
573 "could not find process" in error_output.lower()
574 or "找不到" in error_output

Callers 1

launch_camoufox.pyFile · 0.70

Calls 4

infoMethod · 0.80
warningMethod · 0.80
errorMethod · 0.80
runMethod · 0.45

Tested by

no test coverage detected