[GRASS-dev] [GRASS GIS] #2468: Python OSError: [Errno 7] Argument list too long when running grass.pipe_command repeatedly
GRASS GIS
trac at osgeo.org
Fri Oct 31 15:50:50 PDT 2014
#2468: Python OSError: [Errno 7] Argument list too long when running
grass.pipe_command repeatedly
---------------------------------------------------+------------------------
Reporter: maxnova | Owner: grass-dev@…
Type: defect | Status: new
Priority: normal | Milestone: 6.4.5
Component: Python | Version: 6.4.4
Keywords: OSError, pipe_command, python, script | Platform: Linux
Cpu: x86-64 |
---------------------------------------------------+------------------------
Comment(by glynn):
Replying to [ticket:2468 maxnova]:
> When running grass.pipe_command many times in a row, I get:
>
{{{
OSError: [Errno 7] Argument list too long
}}}
The error message (which comes from strerror) is misleading. From the
documentation for
[http://pubs.opengroup.org/onlinepubs/9699919799/functions/exec.html
execve]:
{{{
[E2BIG]
The number of bytes used by the new process image's argument list and
environment list is greater than the system-imposed limit of {ARG_MAX}
bytes.
}}}
In this case, it's the environment which is too large, not the argument
list.
This is caused by calling grass.script.setup.init() for each iteration.
That function appends the GRASS-specific directories to PATH,
LD_LIBRARY_PATH (or equivalent) and PYTHONPATH, even if they're already
present. So those variables' values get larger with each iteration.
This isn't a bug in grass.pipe_command (etc); you would have exactly the
same problem if you invoked subprocess.Popen() (or os.system(), or any
other interface for executing commands).
The solution is not to invoke grass.script.setup.init() for each
iteration. Instead, just create a new gisrc file with
grass.script.setup.write_gisrc() and set os.environ['GISRC'] to the
filename. IOW, duplicate the last two lines of grass.script.setup.init().
--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2468#comment:1>
GRASS GIS <http://grass.osgeo.org>
More information about the grass-dev
mailing list