mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
python: Remove 'del g' from the docs, replace with 'g.close ()'.
'del g' is a trap for the unwary. If the handle has any other references, it does nothing (in fact, it can be actively dangerous if the user was expecting the appliance to go away). In non-CPython it can be delayed arbitrarily long. Using 'g.close()' on the other hand is always safe.
This commit is contained in:
@@ -58,4 +58,4 @@ g.upload ("/etc/resolv.conf", "/foo/resolv.conf")
|
||||
# Because 'autosync' was set (above) we can just close the handle
|
||||
# and the disk contents will be synchronized. You can also do
|
||||
# this manually by calling g.umount_all and g.sync.
|
||||
del g
|
||||
g.close ()
|
||||
|
||||
@@ -31,6 +31,6 @@ g.lvcreate ("LV1", "VG", 200)
|
||||
g.lvcreate ("LV2", "VG", 200)
|
||||
if (g.lvs () != ["/dev/VG/LV1", "/dev/VG/LV2"]):
|
||||
raise "Error: g.lvs() returned incorrect result"
|
||||
del g
|
||||
g.close ()
|
||||
|
||||
os.unlink ("test.img")
|
||||
|
||||
@@ -22,4 +22,4 @@ g = guestfs.GuestFS()
|
||||
g.add_drive_opts ("/dev/null")
|
||||
g.add_drive_opts ("/dev/null", readonly = 1)
|
||||
g.add_drive_opts ("/dev/null", iface = "virtio", format = "qcow2")
|
||||
del g
|
||||
g.close ()
|
||||
|
||||
@@ -53,6 +53,6 @@ g.set_autosync (1)
|
||||
# Close the handle. The close callback should be invoked.
|
||||
if close_invoked != 0:
|
||||
raise "Error: close_invoked should be 0"
|
||||
del g
|
||||
g.close ()
|
||||
if close_invoked != 1:
|
||||
raise "Error: close_invoked should be 1"
|
||||
|
||||
Reference in New Issue
Block a user