-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
0.3.5: processes of the "w" Windows launcher executables can't be killed anymore #175
Comments
Pinging @vsajip, since he doesn't have the repo on his watch list and probably wasn't notified. |
Whoops, not sure why I wasn't watching - I've rectified that. Thanks for the tip. |
It's a bit tricky to see what's going on. With the |
OK ... it looks as if in the venv case, the Python interpreter is re-invoking the script using the base interpreter - I will put together a test case for this. |
Do you experience the same with your GUI executables, @cbrnr ? |
I will check. What are the steps to reproduce this problem? |
Thanks. Just launch a GUI executable (built using a recent |
I seem to have got closer to finding the cause of this problem. I have set up a test repository with some GitHub test steps. The summary is:
The same launchers (from What changed is that from Python 3.7.2 onwards,
So, it seems that the I'd appreciate a second opinion from @eryksun and/or @mbikovitsky, as they were involved in the recent changes to the launcher code during work to fix this |
I think there are two related issues here. The first one is in the
That last part is a little bit of speculation on my part, but I have some circumstantial evidence:
If my reasoning is correct, then it will also explain why launching the Python interpreter directly, without going through the venvlauncher, works ( I think the immediate fix is to move the call to The other issue, perhaps more suitable for the CPython project, is the divergence between the |
That suggests that expected behaviour (with respect to
Sure, the |
No, I think the current behaviour of the interpreter is correct. If the interpreter were to always clear the "idle state" on startup, it might introduce subtle bugs in existing code. For instance, consider the following setup:
This works right now because In fact, this is the exact use case that the documentation for
Yep. This means that both the |
This worked in an initial test on my system. Good call 👏 |
Good point. |
I've rebuilt all the launchers with the change that @mbikovitsky suggested, and the above commit adds them to |
Thanks, looks like it's working fine now. 👍 I've added
I've also done a production-build test and built my python application using that distlib commit and killing the process of the "...w.exe" executable now works. |
Python 3.11 uses a new implementation of the py launcher that was developed by Steve Dower. It's implemented in "PC/launcher2.c". It's mostly complete, but still ironing out corner cases and niche features (e.g. the "/usr/bin/env" search is just getting implemented). The venv launchers are still implemented in "PC/launcher.c". It would be nice if the script launcher could bypass the environment launcher. That requires coordinated development, or maybe implementing a common launcher for scripts and virtual environments. |
Oh, right - I had no idea. Do you have any information on the reason for the re-implementation? I've seen no discussion on |
I just took a quick look at |
Thanks for the quick feedback. I think I will implement one more pending change - that timeout in the |
I propose to change #define INPUT_IDLE_TIMEOUT 1000
static void
clear_app_starting_state() {
MSG msg;
HWND hwnd;
DWORD rc;
PostMessageW(0, 0, 0, 0);
GetMessageW(&msg, 0, 0, 0);
/*
* Proxy the child's input idle event.
* See https://github.com/pypa/distlib/issues/175#issuecomment-1204452974
*/
rc = WaitForInputIdle(child_process_info.hProcess, INPUT_IDLE_TIMEOUT);
if (rc == 0) {
/*
* Signal the process input idle event by creating a window and pumping
* sent messages. The window class isn't important, so just use the
* system "STATIC" class.
*/
hwnd = CreateWindowExW(0, L"STATIC", L"PyLauncher", 0, 0, 0, 0, 0,
HWND_MESSAGE, NULL, NULL, NULL);
/* Process all sent messages and signal input idle. */
PeekMessageW(&msg, hwnd, 0, 0, 0);
DestroyWindow(hwnd);
}
} Does this seem reasonable? I tried it like this and local tests seem to work. I'm also assuming that one second is reasonable as a timeout. |
There's no need to pass a finite timeout to |
If the timeout is |
If the child exits, that's the "child never goes idle" case, which returns |
If no finite timeout needs to be passed to |
I've made an additional change to the launchers, implementing the improved control key/message handling as suggested by @eryksun. Please check and confirm that the updated launchers in this commit still work in your use cases. |
Built my python app with distlib @ 37df85a (current master), and everything's working as expected. |
Thanks for the feedback. That's good to know - I'll aim to cut a release before too long. |
Note that this change only affects console scripts. The console script launcher doesn't load "user32.dll" (e.g. it uses no shell32 functions such as The GUI script launcher loads "user32.dll" (for |
I'm a little short of time at the moment. Let's see if not doing the above leads to any reported problems. If anyone wants to work up a PR for the above comment, please feel free. |
@vsajip Wanna close this out, now that 0.3.6 has been released? |
Sure. |
Describe the bug
After the launcher files were updated in 8d2acb5 (0.3.5), processes spawned from the "w" launchers can't be killed anymore. I am facing this issue when trying to spawn and kill the processes from a NodeJS context. Calling
childprocess.kill()
via NodeJS'schild_process
module returns success, but the python process keeps running.This is a major problem for me, because my NodeJS application (GUI application via NW.js / Electron) is running a python CLI application built with the distlib launcher executables, and it needs to use the "w" launchers, because otherwise a console window pops up, which is bad for the user experience.
0.3.3 is the most recent release which is working fine.
0.3.4 had the immediate
3221225477
/0xC0000005
exit code error, and I already had to ignore this version when building standalone installers of my python application. Fortunately, pip had reverted back to distlib 0.3.3 until recently, so installing via pip was no problem either, but now it has merged the distlib 0.3.5 release, which is once again bad, and the issue needs to be fixed.Related (old 0.3.4 issue): takluyver/pynsist#243 (comment)
Apparently, these are the recent launcher changes:
https://bitbucket.org/vinay.sajip/simple_launcher/commits/
To Reproduce
I've created a reproduction repo (already did this for 0.3.4). Please see the build config and build+run scripts for the 0.3.5 issue:
https://github.com/bastimeyer/distlib-bug/tree/53f520efec1a6173b7ca037d26c89a6dec8ca633
The resulting GH action logs:
https://github.com/bastimeyer/distlib-bug/actions/runs/2718462897
0.3.5-t64 (success): https://github.com/bastimeyer/distlib-bug/runs/7467911880?check_suite_focus=true#step:7:1
0.3.5-w64 (failure): https://github.com/bastimeyer/distlib-bug/runs/7467912062?check_suite_focus=true#step:7:1
0.3.3-t64 (success): https://github.com/bastimeyer/distlib-bug/runs/7467911132?check_suite_focus=true#step:7:1
0.3.3-w64 (success): https://github.com/bastimeyer/distlib-bug/runs/7467911332?check_suite_focus=true#step:7:1
Environment
The text was updated successfully, but these errors were encountered: