{"id":5759,"library":"console-ctrl","title":"Console Control","description":"The `console-ctrl` library provides a simple mechanism to send a CTRL-C event to a target console process on Windows without triggering a `KeyboardInterrupt` in the calling Python process. It is currently at version 0.1.0, with its sole release in February 2021, indicating a low and likely inactive release cadence.","status":"maintenance","version":"0.1.0","language":"en","source_language":"en","source_url":"https://github.com/arvinpan/console-ctrl","tags":["windows","process control","ctrl-c","signal","console"],"install":[{"cmd":"pip install console-ctrl","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"send_ctrl_c","correct":"from console_ctrl import send_ctrl_c"}],"quickstart":{"code":"import subprocess\nimport time\nimport sys\n\n# Only run on Windows, as this library is Windows-specific\nif sys.platform == 'win32':\n    from console_ctrl import send_ctrl_c\n\n    print(\"Starting a dummy process...\")\n    # Start a simple Python script that prints every second\n    # and can be terminated by CTRL-C\n    dummy_script = \"\"\"\nimport time\nimport sys\ntry:\n    while True:\n        print('Dummy process running...', flush=True)\n        time.sleep(1)\nexcept KeyboardInterrupt:\n    print('\\nDummy process caught CTRL-C and exiting.', flush=True)\nsys.exit(0)\n\"\"\"\n\n    # Use subprocess.Popen to start the dummy process in a new console\n    # CREATE_NEW_CONSOLE ensures it gets its own console, which is key for send_ctrl_c\n    process = subprocess.Popen(\n        [sys.executable, '-c', dummy_script],\n        creationflags=subprocess.CREATE_NEW_CONSOLE\n    )\n\n    print(f\"Dummy process started with PID: {process.pid}\")\n    time.sleep(3) # Let it run for a few seconds\n\n    print(f\"Sending CTRL-C to process {process.pid}...\")\n    send_ctrl_c(process.pid)\n\n    try:\n        # Wait for the process to terminate, with a timeout\n        return_code = process.wait(timeout=5)\n        print(f\"Process terminated with return code: {return_code}\")\n    except subprocess.TimeoutExpired:\n        print(\"Process did not terminate after sending CTRL-C. Terminating forcefully.\")\n        process.terminate()\n        process.wait()\n\n    print(\"Quickstart complete.\")\nelif sys.platform == 'linux' or sys.platform == 'darwin':\n    print(\"This library is designed for Windows and will not work on Linux/macOS.\")\n    print(\"The quickstart example will not run on this platform.\")\nelse:\n    print(\"Unsupported operating system for this library.\")\n","lang":"python","description":"This quickstart demonstrates how to start a separate Python process in a new console and then use `console-ctrl.send_ctrl_c()` to send a CTRL-C event to it, causing the target process to handle the `KeyboardInterrupt` while the calling script continues uninterrupted. This example is Windows-specific."},"warnings":[{"fix":"Ensure the application using `console-ctrl` is deployed and run only on Windows. For cross-platform process control, consider alternatives like `os.kill` (Unix-like) or more robust process management libraries.","message":"This library is designed exclusively for Windows operating systems and will not function on Linux, macOS, or other Unix-like environments. Its core functionality relies on Windows-specific API calls to generate console control events.","severity":"breaking","affected_versions":"0.1.0"},{"fix":"Use with caution on modern Python environments. Consider vendoring the code if long-term stability or specific Python versions are required, or explore alternative solutions for process control.","message":"The `console-ctrl` library has not seen any updates since its initial release (v0.1.0) in February 2021. This indicates it is not actively maintained, which could lead to compatibility issues with newer Python versions (beyond Python 3.6) or changes in Windows API behavior.","severity":"deprecated","affected_versions":"0.1.0"},{"fix":"Ensure the target process has robust `try...except KeyboardInterrupt` blocks to gracefully handle the received signal and perform any necessary cleanup before exiting.","message":"While `send_ctrl_c` prevents a `KeyboardInterrupt` in the *calling* process, the *target* process still receives a standard CTRL-C event. Mismanaging the target process's `KeyboardInterrupt` handling can lead to unexpected behavior, such as immediate termination without cleanup.","severity":"gotcha","affected_versions":"0.1.0"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}