python-launcher | Python launcher for Unix | Command Line Interface library
kandi X-RAY | python-launcher Summary
kandi X-RAY | python-launcher Summary
Launch your Python interpreter the lazy/smart way!. This project is an implementation of the py command for Unix-based platforms (with some potential experimentation for good measure ). The goal is to have py become the cross-platform command that Python users typically use to launch an interpreter while doing development. By having a command that is version-agnostic when it comes to Python, it side-steps the "what should the python command point to?" debate by clearly specifying that upfront (i.e. the newest version of Python that can be found). This also unifies the suggested command to document for launching Python on both Windows as Unix as py has existed as the preferred command on Windows since 2012 with the release of Python 3.3.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of python-launcher
python-launcher Key Features
python-launcher Examples and Code Snippets
Community Discussions
Trending Discussions on python-launcher
QUESTION
Right, this is extremely obscure...
So on Windows, when you hit control-C to interrupt a console program, this sends a CTRL_C_EVENT
to the process. You can also do this manually via GenerateConsoleCtrlEvent
. In Python, os.kill
acts as a wrapper around the C-level GenerateConsoleCtrlEvent
, and allows us to send a CTRL_C_EVENT
to the current process by doing:
ANSWER
Answered 2017-Apr-24 at 06:27Every process is in a process group. It either inherits its parent's group, or it gets created as the leader of a new group via the CREATE_NEW_PROCESS_GROUP
creation flag. As far as I know, GenerateConsoleCtrlEvent
is the only API that uses process groups, and there's no API to query the process group ID. You could grab it from the ProcessParameters
in the PEB, but that involves using undocumented internal structures. No one should do that, so GenerateConsoleCtrlEvent
should only send to either group 0 to broadcast an event or to a child process that you know was created as a new group.
The problem that you've uncovered here is that sending an event to a process that's attached to the console but not the leader of a group gets silently handled as if the target were group 0. Specifically in your case you're starting py.exe as the group leader and then trying to send CTRL_C_EVENT
to python.exe, i.e. os.getpid()
. You'd have to send to os.getppid()
in this case.
This problem is common with Python scripts on Windows because of the confusing implementation of os.kill
. It conflates process IDs and process group IDs. It would have been less confusing had GenerateConsoleCtrlEvent
been used for os.killpg
(currently not implemented on Windows) and TerminateProcess
alone used for os.kill
.
Experiencing random hangs when calling os.kill(os.getpid(), signal.CTRL_C_EVENT);
time.sleep(10)
may be due to a race condition. time.sleep
is implemented by pysleep
in Modules/timemodule.c. On Windows, when called in the main thread, it waits on an event that gets set by the signal handler for SIGINT
(but not SIGBREAK
for some reason). The possible race here is that pysleep
resets the event before waiting on it. The signal handler executes on a new thread, and occasionally it may have already set the event before pysleep
resets it. This is conceivable since executing CPython bytecode is relatively slow. That said, I'd expect it to be a close race because there are a lot of steps involved to create the control handler thread, as the following overview shows for Windows 10.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install python-launcher
The man page
Shell completions for fish
This README
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page