python argument list_在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

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.

最初,我认为我传递的命令(它是4个文件的绝对路径)比OS支持的时间长。但即使将绝对路径减少到原始值的1/4。我仍然会得到这个错误。请注意,我一直没有得到这个错误。大多数情况下,当路径长度保持不变时,它会运行1000次或更多。

1 个解决方案

#1

2

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.

strace是你的朋友。扔进-s 2048,看看到底发生了什么。知道C可以帮助你阅读这篇文章,但你仍然可以在没有C知识的情况下挑选出很长的exec*字符串。

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

回答: 出现OSError: [Errno 22 Invalid argument错误的原因是在调用open函数时传入了一个带有特殊字符的文件名。Python的strip()函数只能去除字符串首尾的空格,无法去除间的空格,需要使用replace()函数来替换间的空格。另外,\r代表回车,即打印头归位,而\n代表换行。如果想要去除字符串的空格、换行和回车,可以使用replace()函数来处理。至于python打包成exe文件出现OSError: [Errno 22 Invalid argument错误,可能是因为exe文件的输入参数不正确,请检查你的代码是否存在传入带有特殊字符的参数。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Python文件操作错误:OSError: [Errno 22] Invalid argument(关于Windows下文件名的敏感字符)](https://blog.csdn.net/m0_54490473/article/details/122706256)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [python文件保存时,出现OSError:[Errno 22] Invalid argument解决办法](https://blog.csdn.net/bbrry/article/details/125690638)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值