diff options
author | Wojtek Porczyk <woju@invisiblethingslab.com> | 2017-09-14 02:29:29 +0200 |
---|---|---|
committer | Daniel P. Berrange <berrange@redhat.com> | 2017-09-26 11:01:33 +0100 |
commit | 7f1994ff462b792bcf5963bef602b3fefeb6ef1e (patch) | |
tree | 6f49a09db832568542daa8a45d12dad8496bf8c4 /libvirtaio.py | |
parent | fc482fc8688e9ba25ee19f34e5a692504ec85da3 (diff) | |
download | libvirt-python-7f1994ff462b792bcf5963bef602b3fefeb6ef1e.tar.gz |
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 <woju@invisiblethingslab.com>
Diffstat (limited to 'libvirtaio.py')
-rw-r--r-- | libvirtaio.py | 16 |
1 files changed, 14 insertions, 2 deletions
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 <woju@invisiblethingslab.com>' __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 |