简体   繁体   English

当必须重新启动脚本时,如何避免“[Errno 7] 参数列表太长”?

[英]How to avoid a "[Errno 7] Argument list too long" when a script has to be restarted?

I have a script which runs without any problems for several days/weeks.我有一个脚本可以运行几天/几周没有任何问题。 Based on some definitions, I need to restart this entire script.根据一些定义,我需要重新启动整个脚本。 The restart itself is realized with the following line.重新启动本身是通过以下行实现的。 And this works in most cases without any problems.这在大多数情况下都有效,没有任何问题。

os.execv(sys.executable, ['python'] + sys.argv)

Sometimes it is not successful and I see the following error message.有时它不成功,我看到以下错误消息。 I cannot find any distinguisher between the moments when it works fine and when not.我无法在它工作正常的时刻和不正常的时刻之间找到任何区别。

Traceback (most recent call last):
  File "/opt/rh/rh-python36/root/usr/lib64/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/opt/rh/rh-python36/root/usr/lib64/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "abc.py", line 301, in pinging
    os.execv(sys.executable, ['python'] + sys.argv)
OSError: [Errno 7] Argument list too long

What could I change in the code or how should I restart a script to prevent this error message?我可以在代码中进行哪些更改,或者我应该如何重新启动脚本以防止出现此错误消息?

The problem is问题是

Everytime os.execv runs, a new script starts, but the actual running script is not stopped.每次运行os.execv时,都会启动一个新脚本,但不会停止实际运行的脚本。 So by this sys.argv is becoming longer until it gives the error.所以通过这个sys.argv变得更长,直到它给出错误。

The solution is解决方案是

Avoid that a new script starts by handling the situation in another way.通过以另一种方式处理情况来避免新脚本开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 OSError: [Errno 7] 参数列表太长:'php' - Python 3.6 - OSError: [Errno 7] Argument list too long: 'php' - Python 3.6 为什么在使用mrjob v0.4.4时,[Errno 7]参数列表过长且OSError:[Errno 24]打开的文件太多? - Why am I getting [Errno 7] Argument list too long and OSError: [Errno 24] Too many open files when using mrjob v0.4.4? 间歇性“OSError: [Errno 7] Argument list too long”和短命令(~125 个字符) - Intermittent “OSError: [Errno 7] Argument list too long” with short command (~125 chars) OSError:[Errno 7] ubuntu上的参数列表太长,python用popen调用bitcoind-cli - OSError: [Errno 7] Argument list too long on ubuntu, python calling bitcoind-cli with popen 为什么我收到 OSError: [Errno 7] 参数列表太长:b'/usr/local/bin/git'? - Why I`m getting OSError: [Errno 7] Argument list too long: b'/usr/local/bin/git'? shell:参数列表太长 - shell: Argument list too long 将查找输出作为参数传递时出现“参数列表太长”错误 - "Argument list too long" error when passing a find output as arguments 读取 XML 响应时,Mitmproxy 脚本返回“OSError: [Errno 63] File name too long” - Mitmproxy script returns "OSError: [Errno 63] File name too long" when XML response is read env:python:参数列表过长 - env: python: Argument list too long `参数列表太长:'/bin/sh'` - `Argument list too long: '/bin/sh'`
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM