Intermittent "OSError: [Errno 7] Argument list too long" with short command (~125 chars)

We had a similar problem and bothered us for a quite while too. Today, we found the root cause.

The error message is little bit misleading, it is not command line's "argument" too long, it is actually the OS environment passed along with command. In this case, Python os.environ. In our code base, there is one line code:

os.environ['PATH'] =  ':'.join([os.environ['PATH'], self.clitoolsdir])

It is part of a class's __init__(). Anytime a new object was created, os.environ got longer, eventually it became "too long".