Avoid deprecation warnings for asyncio.async() in server mode (#202)

This is actually needed for Python 3.7 which introduces async and await
as  reserved keywords, see https://docs.python.org/3/whatsnew/3.7.html
async-mib-instrumentation
Fabrizio Vanni 2018-09-26 11:12:30 +02:00 committed by Ilya Etingof
parent 53e67f9533
commit 35e9c6f7a6
1 changed files with 5 additions and 1 deletions

View File

@ -101,7 +101,11 @@ class DgramAsyncioProtocol(asyncio.DatagramProtocol, AbstractAsyncioTransport):
c = self.loop.create_datagram_endpoint(
lambda: self, local_addr=iface, family=self.sockFamily
)
self._lport = getattr(asyncio, 'async')(c)
# Avoid deprecation warning for asyncio.async()
if IS_PYTHON_344_PLUS:
self._lport = asyncio.ensure_future(c)
else: # pragma: no cover
self._lport = getattr(asyncio, 'async')(c)
except Exception:
raise error.CarrierError(';'.join(traceback.format_exception(*sys.exc_info())))
return self