I am running rclone copy --rc. At same time I am running a for-loop to run rclone rc core/stats. But I want to break the for-loop of rclone rc core/stats when the task of rclone copy --rc is ended (killed or done).
There is such information printed after rclone copy --rc is ended, Failed to rc: connection failed: Post http://localhost:5572/core/stats: dial tcp [::1]:5572: connect: connection refused
But I do not know how to catch this information?
cnt_error = 0
while True:
cmd = 'rclone rc core/stats'
try:
response = subprocess.check_output(cmd, shell=True)
cnt_error = 0
except subprocess.CalledProcessError as error:
cnt_error = cnt_error + 1
continue
if cnt_error >= 3:
print('3 times over')
break
What is your rclone version (output from rclone version)
rclone v1.49.0-016-gf97a3e85-beta
os/arch: linux/amd64
go version: go1.12.9
Which OS you are using and how many bits (eg Windows 7, 64 bit)
Ubuntu 16.04
Which cloud storage system are you using? (eg Google Drive)
Google Drive
The command you were trying to run (eg rclone copy /tmp remote:tmp)
But the try and except cannot catch that subprocess.CalledProcessError at all. Because the for-loop is never stopped even though the cmd rclone copy --rc is ended. So I come here asking for some help.
SubprocessError will catch all related errors from subprocess (eg timeout), whereas CalledProcessError is a specialized version of that which will only catch error exit codes from the process and other errors should bubble up.
>>> subprocess.check_output(["false"])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.7/subprocess.py", line 395, in check_output
**kwargs).stdout
File "/usr/lib/python3.7/subprocess.py", line 487, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['false']' returned non-zero exit status 1.