本文介绍了Linux中的Python OSError No 7(参数列表过长)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试打开一个新的子进程,该子进程将使用一些输入文件,并在其他文件中生成输出.尽管大多数情况下运行情况都很好,但是当我尝试进行一些压力测试时却失败了,并给出了以下错误跟踪:

I am trying to open a new subprocess which will take a few input files and generate the output in other file. While this runs cleanly most of the times, when I am trying to do some stress testing this fails and gives me the following error trace:

File "/home/admin/Workspace/.metadata/.plugins/org.eclipse.pde.core/pde-junit/org.eclipse.osgipython/util/media_info.py", line 161, in external_process

    process = subprocess.Popen(command, shell=shell, close_fds=True, stderr=subprocess.PIPE)

  File "/usr/local/lib/python2.6/subprocess.py", line 623, in __init__
    errread, errwrite)

  File "/usr/local/lib/python2.6/subprocess.py", line 1141, in _execute_child
    raise child_exception

OSError: [Errno 7] Argument list too long

最初,我认为我正在传递的命令(这是4个文件的绝对路径)比操作系统所能支持的时间更长.但是即使减小绝对路径,也可以传递到原始值的1/4.我仍然收到此错误.请注意,我不会一直收到此错误.通常在运行1000次或更多之后,路径长度在所有情况下都保持不变.

Initially I thought that the command that I was passing(it was the absolute path of 4 files) was longer than the OS could support. But even after reducing the absolute path passed to 1/4th of the original value. I still get this error. Please note that I don't get this error all the time. Mostly its after a 1000 or more runs while the path length remains the same for all cases.

推荐答案

strace是您的朋友.放入-s 2048以查看实际情况.了解C可以帮助您阅读此书,但是您仍然可以在不具备C知识的情况下挑选长exec *字符串.

strace is your friend. Throw in a -s 2048 to see what's really happening. Knowing C will help you read this, but you can still pick out long exec* strings without C knowledge.

http://stromberg.dnsalias.org/~strombrg/debugging-with-syscall-tracers.html

这篇关于Linux中的Python OSError No 7(参数列表过长)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 02:25