From 3bb431f9ff65e5ae2c4a554189a6ae23e6c00108 Mon Sep 17 00:00:00 2001 From: kaliko Date: Tue, 6 Nov 2018 14:24:17 +0100 Subject: [PATCH] Switch to async/await --- musicpdaio.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/musicpdaio.py b/musicpdaio.py index 4339f72..5e2c480 100644 --- a/musicpdaio.py +++ b/musicpdaio.py @@ -60,6 +60,7 @@ class Response: ' '.join(self.resp.split('\n')[:2]), self.version) + class MPDProto(asyncio.Protocol): def __init__(self, future, payload): logging.debug('payload: "%s"', payload) @@ -135,14 +136,13 @@ class MPDClient: (self.__class__.__name__, attr)) return lambda *args: wrapper(command, args) - @asyncio.coroutine - def _connect(self, proto): + async def _connect(self, proto): # coroutine allowing Exception handling # src: http://comments.gmane.org/gmane.comp.python.tulip/1401 try: - yield from self._evloop.create_connection(lambda: proto, - host=self._host, - port=self._port) + await self._evloop.create_connection(lambda: proto, + host=self._host, + port=self._port) except Exception as err: proto.future.set_exception(ConnectionError(err)) @@ -169,8 +169,8 @@ class MPDClient: """Run event loop gathering tasks from self.futures """ if self.futures: - self._evloop.run_until_complete(asyncio.gather(*self.futures)) - self.futures = [] + self._evloop.run_until_complete(asyncio.gather(*self.futures)) + self.futures = [] else: logging.info('No task found in queue, need to set self.asio?') -- 2.39.2