1
0
mirror of https://gitlab.com/libvirt/libvirt-python.git synced 2025-07-29 19:41:52 +03:00

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>
This commit is contained in:
Wojtek Porczyk
2017-09-14 02:29:29 +02:00
committed by Daniel P. Berrange
parent fc482fc868
commit 7f1994ff46

View File

@ -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