The Mysterious Case of <"OSError: [Errno 7] Argument list too long"> while calling subprocess from Python

Ran into this little kinky bastard a few days now. Got me keep scratching my head as to why I am calling a simple command from Python to call subprocess in the form of COMMAND ARG1 ARG2 (with ZERO path information, so super short) yet it failed with that error spectacularly.

I spend ages digging into how come such short commands would evoke this kind of problem, it turns out, it has nothing to do with the subprocess call or the way I called them.

I actually had a BUG in the previous lines where I attempted to add the path to COMMAND to the $PATH and this was called way too many time resulted in a $PATH variable that is insanely long mostly composed of PATH/TO/COMMAND being repettively added THOUSANDS of times to the $PATH variable for the current python session.

In short, I attempted to add the path to the command thousands of times to the $PATH variable and THAT was actually the root cause of the bug where [Errno 7] Argument List too long come from.

So, check how you are adding the path to your command where you can calling and ensure this is not the cause of the ERRNO7.

Case closed, I hope.