mirror of
https://gitlab.com/libvirt/libvirt-python.git
synced 2025-08-05 16:21:59 +03:00
examples: Do not use bare except
as it also catches SystemExit, InterruptedError, SyntaxError and such. Signed-off-by: Philipp Hahn <hahn@univention.de>
This commit is contained in:
committed by
Philipp Hahn
parent
06aba185a8
commit
4e22f4de6f
@ -55,7 +55,7 @@ def stream_callback(stream: libvirt.virStream, events: int, console: Console) ->
|
|||||||
try:
|
try:
|
||||||
assert console.stream
|
assert console.stream
|
||||||
received_data = console.stream.recv(1024)
|
received_data = console.stream.recv(1024)
|
||||||
except:
|
except Exception:
|
||||||
return
|
return
|
||||||
os.write(0, received_data)
|
os.write(0, received_data)
|
||||||
|
|
||||||
|
@ -80,13 +80,13 @@ def processAgentConnect(dom):
|
|||||||
libvirt.VIR_DOMAIN_AFFECT_LIVE)
|
libvirt.VIR_DOMAIN_AFFECT_LIVE)
|
||||||
doc = minidom.parseString(cpus)
|
doc = minidom.parseString(cpus)
|
||||||
ncpus = int(doc.getElementsByTagName('ncpus')[0].getAttribute('count'))
|
ncpus = int(doc.getElementsByTagName('ncpus')[0].getAttribute('count'))
|
||||||
except:
|
except Exception:
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
dom.setVcpusFlags(ncpus, libvirt.VIR_DOMAIN_AFFECT_LIVE | libvirt.VIR_DOMAIN_VCPU_GUEST)
|
dom.setVcpusFlags(ncpus, libvirt.VIR_DOMAIN_AFFECT_LIVE | libvirt.VIR_DOMAIN_VCPU_GUEST)
|
||||||
print("set vcpu count for domain " + dom.name() + " to " + str(ncpus))
|
print("set vcpu count for domain " + dom.name() + " to " + str(ncpus))
|
||||||
except:
|
except Exception:
|
||||||
print("failed to set vcpu count for domain " + dom.name())
|
print("failed to set vcpu count for domain " + dom.name())
|
||||||
|
|
||||||
def work():
|
def work():
|
||||||
@ -98,7 +98,7 @@ def work():
|
|||||||
if not data.hasConn():
|
if not data.hasConn():
|
||||||
try:
|
try:
|
||||||
conn = libvirt.open(uri)
|
conn = libvirt.open(uri)
|
||||||
except:
|
except libvirt.libvirtError:
|
||||||
print('Failed to connect to ' + uri + ', retry in ' + str(connectRetryTimeout)) + ' seconds'
|
print('Failed to connect to ' + uri + ', retry in ' + str(connectRetryTimeout)) + ' seconds'
|
||||||
time.sleep(connectRetryTimeout)
|
time.sleep(connectRetryTimeout)
|
||||||
continue
|
continue
|
||||||
|
Reference in New Issue
Block a user