Nuitka: Child process dont finished when parent close
- Nuitka version, full Python version and Platform (Windows, OSX, Linux …)
python -m nuitka --version 0.6.11.2 Python: 3.8.6 (default, Oct 1 2020, 13:01:33) [GCC 10.2.0 64 bit (AMD64)] Executable: D:/PYTHON/picta-dl/env/bin/python.exe OS: Windows Arch: x86_64
- How did you install Nuitka and Python
Using virtualenv
- Also supply a Short, Self Contained, Correct, Example
#!/usr/bin/env python
# child.py
# Compile with Nuitka:
# python -m nuitka --onefile --mingw64 --assume-yes-for-downloads --windows-company-name=MyCompany --windows-product-name=child --windows-product-version=1.0.0.0 --windows-file-description="Child" child.py
import time
def main_ok():
try:
while True:
print('Im working...')
time.sleep(2)
except KeyboardInterrupt:
print('Exit from child!')
def main():
# Dont work with CTRL_C_EVENT ??!
while True:
print('Im working...')
time.sleep(2)
if __name__ == '__main__':
main()
- Freeze
python -m pip freeze Nuitka==0.6.11.2
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (9 by maintainers)
Released as part of 0.6.12
Part of the current pre-release, I expect to make a release relatively soon.
If you consider going the commercial route, visit this https://nuitka.net/pages/commercial.html
Nuitka aims at full compatibility, i.e. it will give precisely the same stack traces as normal Python does. Actually e.g. including source code in the standalone distribution is something that I want to implement.
If you want to hide information, the Nuitka commercial plugins will cover that, and there is currently early bird work for these going on. They will e.g. also allow encrypted outputs of tracebacks, so you could decode them, but not your clients. If you yourself, e.g. not willing to buy those, can catch and swallow all exceptions, that will of course often also work.
So in my testing, this works when you CTRL-C from the terminal. CPython only implements sending CTRL-C to processes in the same group, otherwise it’s hard kills. From task manager, killed processes get hard killed, only apps get soft killed it seems, but you have to appear there first. That seems to be as good as you can get in an obvious way.
What we could attempt is a monitoring (C only) thread in the Python part that will detect if the parent process is gone, and it if it is, to goes to a Python and injects the
KeyboardInteruptmanually, and potentially even ensures the file system cleanup, although deleting running code is not going to come easy, but it can be scheduled for the next boot I guess.Adding that kind of thread should be easy. For Windows Services in Nuitka Commercial, we already have similar stuff, I can take it from there.
In my manual testing, CTRL-C on a sleeping process gave it
KeyboardInterruptexception, and that’s what I am adding automated tests for now, also to prove my Linux ideas. I am not entirely sure what CTRL-Break is, but since the code also handles logoff and system restart, I think GUI applications without console out to also working.