-
Notifications
You must be signed in to change notification settings - Fork 374
"OSError: [WinError 6] The handle is invalid" when running invoke #683
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
Comments
I'm also seeing this in python 3.8.0/invoke 1.3.0. Repro is as simple as running "invoke build" with the following tasks.py file. Exception occurs randomly, and frequently. This happens for nearly all the commands in my tasks.py file, and never generates any warning messages. I've had to wrap all my commands with try/except blocks in order to see the output when it occurs.
Output:
|
There is a race condition between process_is_finished and has_dead_threads, at least on windows. The check for the process being finished returns False, then the stdio and stderr threads "die", so the process exists without a valid error code. Return code is None, then all the tasks abort without any error messages, even though the processes have completed successfully. This happens so frequently that it makes invoke almost entirely unusable on Windows. This workaround is not a great solution, by all accounts. If it detects that there are dead threads, but the process is not finished, it simply continues polling for another 3 seconds to wait for the process to complete gracefully. As I don't know the code that well, I'm willing to bet there's a better solution to this problem than just polling for an arbitrary amount of time. However, I've been using it all morning, in two different projects, and it seems to be working fine.
I've hacked up a workaround. Essentially, there's a race condition in 1.3.0 where the stdio and stderr threads "die" before the process does, and this exits the polling loop, causing the return code to be None. My change (clearly not for primetime) simply polls the process up to an additional 3 seconds to wait for it to complete. Details are in the commit message. I've tried 1.3.0 on multiple machines (Windows 10, Python 3.7.x and 3.8.x) and it's failing regularly even with a simple task and nearly always when there are multiple tasks chained together. With this workaround, everything is much more stable. |
Also encountering "Encountered a bad command exit code!" (None) on macOS |
I think I'm seeing the same or a similar thing on archlinux, also invoke 1.3, python 3.8.1.
I can get it to repeat pretty consistently with this small task:
The
However, that's not fixing the problem consistently in my actual tasks. This is what I see in debug mode:
It doesn't run the command after the |
This def feels like #660 - thanks for the extra reports, please follow that issue. |
I sometimes get the following error, when I execute invoke on a windows machine. This error causes to abruptly terminate the following tasks (without further notice). If I run invoke with debug and echo flags I get the following output (see below).
My environment:
python 3.8.0 (and I also tried python 3.6.1)
Invoke 1.3.0
The error message (with -d and -e flag):
invoke.program.run: Received a possibly-skippable exception: <UnexpectedExit: cmd='cd C:\\work\\git\\template\\build && C:\\work\\git\\template\\set_env.bat && cmake -G "Ninja" ..' exited=None> Exception ignored in: <function Popen.__del__ at 0x03D1A9B8> Traceback (most recent call last): File "C:\tools\python\lib\subprocess.py", line 945, in __del__ self._internal_poll(_deadstate=_maxsize) File "C:\tools\python\lib\subprocess.py", line 1344, in _internal_poll if _WaitForSingleObject(self._handle, 0) == _WAIT_OBJECT_0: OSError: [WinError 6] The handle is invalid
The text was updated successfully, but these errors were encountered: