On Fri, Feb 04, 2022 at 12:49:27AM +0200, Nir Soffer wrote:
On Thu, Feb 3, 2022 at 10:26 PM Eric Blake <eblake(a)redhat.com>
wrote:
>
> Like a lot of the C examples, the aio copy test ignores read and write
> errors in the completion callback, which can cause silent data
> corruption. The failure in the test is not critical, but this is a bad
> example that may be copied by developers to a real application.
>
> @@ -36,6 +36,7 @@ def asynch_copy(src, dst):
> # This callback is called when any pread from the source
> # has completed.
> def read_completed(buf, offset, error):
> + assert not error
This works for the test, since the test is not compiled
to pyc file, which removes the asserts (like C -DNODBUG)
by default when building rpms.
If someone will copy this to a real application they will have no
error checking.
I would use:
if error != 0:
raise RuntimeError(f"read: {os.strerror(error)}")
Which also teaches the reader that error is an errno value.
Will do (I trust your python expertise more than my own ;)
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization:
qemu.org |
libvirt.org