From 7f1994ff462b792bcf5963bef602b3fefeb6ef1e Mon Sep 17 00:00:00 2001 From: Wojtek Porczyk Date: Thu, 14 Sep 2017 02:29:29 +0200 Subject: libvirtaio: keep track of the current implementation Since 7534c19 it is not possible to register event implementation twice. Instead, allow for retrieving the current one, should it be needed afterwards. Signed-off-by: Wojtek Porczyk --- libvirtaio.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'libvirtaio.py') diff --git a/libvirtaio.py b/libvirtaio.py index a7ede41..97a7f6c 100644 --- a/libvirtaio.py +++ b/libvirtaio.py @@ -30,7 +30,11 @@ Register the implementation of default loop: __author__ = 'Wojtek Porczyk ' __license__ = 'LGPL-2.1+' -__all__ = ['virEventAsyncIOImpl', 'virEventRegisterAsyncIOImpl'] +__all__ = [ + 'getCurrentImpl', + 'virEventAsyncIOImpl', + 'virEventRegisterAsyncIOImpl', +] import asyncio import itertools @@ -401,10 +405,18 @@ class virEventAsyncIOImpl(object): callback = self.callbacks.pop(timer) callback.close() + +_current_impl = None +def getCurrentImpl(): + '''Return the current implementation, or None if not yet registered''' + return _current_impl + def virEventRegisterAsyncIOImpl(loop=None): '''Arrange for libvirt's callbacks to be dispatched via asyncio event loop The implementation object is returned, but in normal usage it can safely be discarded. ''' - return virEventAsyncIOImpl(loop=loop).register() + global _current_impl + _current_impl = virEventAsyncIOImpl(loop=loop).register() + return _current_impl -- cgit v1.2.1