Registry / devops / console-ctrl

console-ctrl

JSON →
library0.1.0pypypi✓ verified 23d ago

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.

pip install console-ctrl
INSTALL
IMPORT
SIG · CONSOLE-CTRL
C
console-ctrl
devopspythonv0.1.0
Install
1.5s avg
Import
16ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.016s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.016s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

send_ctrl_c
from console_ctrl import send_ctrl_c

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.

import subprocess import time import sys # Only run on Windows, as this library is Windows-specific if sys.platform == 'win32': from console_ctrl import send_ctrl_c print("Starting a dummy process...") # Start a simple Python script that prints every second # and can be terminated by CTRL-C dummy_script = """ import time import sys try: while True: print('Dummy process running...', flush=True) time.sleep(1) except KeyboardInterrupt: print('\nDummy process caught CTRL-C and exiting.', flush=True) sys.exit(0) """ # Use subprocess.Popen to start the dummy process in a new console # CREATE_NEW_CONSOLE ensures it gets its own console, which is key for send_ctrl_c process = subprocess.Popen( [sys.executable, '-c', dummy_script], creationflags=subprocess.CREATE_NEW_CONSOLE ) print(f"Dummy process started with PID: {process.pid}") time.sleep(3) # Let it run for a few seconds print(f"Sending CTRL-C to process {process.pid}...") send_ctrl_c(process.pid) try: # Wait for the process to terminate, with a timeout return_code = process.wait(timeout=5) print(f"Process terminated with return code: {return_code}") except subprocess.TimeoutExpired: print("Process did not terminate after sending CTRL-C. Terminating forcefully.") process.terminate() process.wait() print("Quickstart complete.") elif sys.platform == 'linux' or sys.platform == 'darwin': print("This library is designed for Windows and will not work on Linux/macOS.") print("The quickstart example will not run on this platform.") else: print("Unsupported operating system for this library.")
Debug
Known issues
breakingThis 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.
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.
affects: 0.1.0
deprecatedThe `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.
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.
affects: 0.1.0
gotchaWhile `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.
fix
Ensure the target process has robust `try...except KeyboardInterrupt` blocks to gracefully handle the received signal and perform any necessary cleanup before exiting.
affects: 0.1.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'console_ctrl'
The `console-ctrl` package has not been installed in your current Python environment.
fix
Install the package using pip: `pip install console-ctrl`
OSError: [WinError 126] The specified module could not be found.
The `console-ctrl` library is exclusively designed for Windows and attempts to load Windows API libraries (like `kernel32.dll`) which are unavailable on non-Windows operating systems.
fix
Ensure your application is running on a Windows operating system. For cross-platform process control, consider using `os.kill` for Unix-like systems.
OSError: [WinError 87] The parameter is incorrect
The `send_ctrl_c` function was called with a Process ID (PID) that does not correspond to a process in a new console session, likely because the target process was not started with the required `creationflags=subprocess.CREATE_NEW_CONSOLE` flag.
fix
When starting the target process using `subprocess.Popen`, ensure `creationflags=subprocess.CREATE_NEW_CONSOLE` is included. Pass the `pid` of this newly created process to `console_ctrl.send_ctrl_c`.
AttributeError: module 'console_ctrl' has no attribute 'send_ctrl_c'
The `send_ctrl_c` function was called with a typo, or the module was imported incorrectly.
fix
Correct the function name to `console_ctrl.send_ctrl_c`. Verify the exact spelling and casing against the library's documentation.
Upgrade
Version history
0.1.0latest on PyPI · released Feb 21, 2021
Audit
Dependencies

No dependency data recorded yet.

Agent activity
33 hits · last 30 days
node
30
OpenAI (training)
1
Resources
console-ctrl — pip install console-ctrl · libregistry