[英]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.