OSError: [WinError 6] The handle is invalid when calling subprocess from Python 3.6 OSError: [WinError 6] The handle is invalid when calling subprocess from Python 3.6 python-3.x python-3.x

OSError: [WinError 6] The handle is invalid when calling subprocess from Python 3.6


After a bit of pause, I quickly found the reason behind this.

It was because of the GitPython usage in the project which didn't call git.Repo.close() or used git.Repo as a context manager.There is a warning about this on GitPython's readme.

It was helpful to add logging in subprocess's _internal_poll method to know which process (args) is the culprit. For GitPython it was git cat-file ...