Nir Soffer has uploaded a new change for review.
Change subject: libvirtconnection: Replace assert with AssertionError ......................................................................
libvirtconnection: Replace assert with AssertionError
The code wrongly assumed that assert always exists. When running in optimized mode, the check would be skipped, and instead of getting an AssertionError, which is the expected error for programmer error (starting the eventloop twice), we could get a confusing RuntimeException or RuntimeError from Thread.start (depending on Python version).
RuntimeError misused in the standard library for all kinds of errors that do not have builtin errors. It is particularry bad option when used for usage error.
Change-Id: Icf1564f81f4c1fbf77ccaff6d93c047a02d946da Signed-off-by: Nir Soffer nsoffer@redhat.com --- M lib/vdsm/libvirtconnection.py 1 file changed, 2 insertions(+), 1 deletion(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/64/34364/1
diff --git a/lib/vdsm/libvirtconnection.py b/lib/vdsm/libvirtconnection.py index 5430c82..009f8b7 100644 --- a/lib/vdsm/libvirtconnection.py +++ b/lib/vdsm/libvirtconnection.py @@ -37,7 +37,8 @@ self.__thread = None
def start(self): - assert not self.run + if self.run: + raise AssertionError("EventLoop is running") self.__thread = threading.Thread(target=self.__run, name="libvirtEventLoop") self.__thread.setDaemon(True)