I am using an automation framework and I am getting random error after many iterations which is as follows. Can someone help me understand what this could correspond to !!
_os.environ['PATH'] = r'C:\DAL;' + _os.environ['PATH']
File "c:\Python26\lib\os.py", line 420, in __setitem__
putenv(key, item)
OSError: [Errno 22] Invalid argument
Function Call where it fails:
function:
plugin_xml_file_name = plugin_name
else:
plugin_xml_file_name = plugin_path + "\\" + plugin_name
#
_os.environ['PATH'] = r'C:\Intel\DAL;' + _os.environ['PATH']
_os.environ['PATH'] = r'C:\intel\dal;' + _os.environ['PATH']
_os.environ['PATH'] = _lakemore_path + ';' + _os.environ['PATH']
_os.environ['PATH'] = plugin_path + ';' + _os.environ['PATH']
解决方案
You are creating too long a path and the OS no longer accepts a longer environment variable.
Extend the path only once. Test for the presence of the paths you are adding:
path = _os.environ['PATH'].split(_os.pathsep)
for extra in (r'C:\Intel\DAL', r'C:\intel\dal', _lakemore_path, plugin_path):
if extra not in path:
_os.environ['PATH'] = _os.pathsep.join(extra, _os.environ['PATH'])
This code only adds new elements if not already present.