성공적인 출력까지 코드 블록을 반복하고 싶지만 성공적인 메시지 만 표시하고 싶습니다.
while i < 6:
try:
sys.tracebacklimit = 0 #this line seems not work
gluster_volume_names = []
gstatus_output = subprocess.check_output('gstatus -a -o json ', shell=True).decode()
date, time, json_part = gstatus_output.split(maxsplit=2)
gluster_info = json.loads(json_part)
volume_list = gluster_info["volume_summary"]
....
....
break
except:
i += 1
continue
그러나 아래에서 이러한 출력을 억제하는 방법을 모르겠습니다. (실패한 실행) 그들은 내가 원하는 결과가 아닙니다. 코드 블록은 결국 5 회 미만의 시도 후에 성공적으로 실행 된 후 종료됩니다.
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/gstatus-0.66-py3.6.egg/EGG-INFO/scripts/gstatus", line 143, in main
File "/usr/local/lib/python3.6/site-packages/gstatus-0.66-py3.6.egg/gstatus/libgluster/cluster.py", line 543, in update_state
gstatus.libutils.excepts.GlusterFailedVolume: Unable to query volume 'BLAH'
Possible cause: cluster is currently reconverging after a nodehas entered a disconnected state.
Response: Rerun gstatus or issue a peer status command to confirm
도와주세요!
를 사용하는 대신 subprocess.check_output
표준 subprocess.run
방법을 사용 하고 표준 오류를 / dev / null로 파이프 해야합니다 . 대신 다음을 사용하십시오.
gstatus_output = subprocess.run('gstatus -a -o json ', shell=True, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL).stdout.decode()
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다