8000 Backwards compatibility with Python versions that don't have asyncio.… · chdsbd/asyncio-redis@82bd302 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Commit 82bd302

Browse files
Backwards compatibility with Python versions that don't have asyncio.ensure_future yet. (Fallback to asyncio.async.)
1 parent 601eafe commit 82bd302

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

asyncio_redis/protocol.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@
5858

5959
NoneType = type(None)
6060

61+
# In Python 3.4.4, `async` was renamed to `ensure_future`.
62+
try:
63+
ensure_future = asyncio.ensure_future
64+
except AttributeError:
65+
ensure_future = asyncio.async
66+
6167

6268
class ZScoreBoundary:
6369
"""
@@ -634,7 +640,7 @@ def done(result):
634640
typecheck_return(protocol_self, result)
635641
future2.set_result(result)
636642

637-
future.add_done_callback(lambda f: asyncio.ensure_future(done(f.result()), loop=protocol_self._loop))
643+
future.add_done_callback(lambda f: ensure_future(done(f.result()), loop=protocol_self._loop))
638644

639645
return future2
640646

@@ -806,7 +812,7 @@ def connection_made(self, transport):
806812
# Start parsing reader stream.
807813
self._reader = StreamReader(loop=self._loop)
808814
self._reader.set_transport(transport)
809-
self._reader_f = asyncio.ensure_future(self._reader_coroutine(), loop=self._loop)
815+
self._reader_f = ensure_future(self._reader_coroutine(), loop=self._loop)
810816

811817
@asyncio.coroutine
812818
def initialize():
@@ -825,7 +831,7 @@ def initialize():
825831
if self._pubsub_patterns:
826832
yield from self._psubscribe(self._subscription, list(self._pubsub_patterns))
827833

828-
asyncio.ensure_future(initialize(), loop=self._loop)
834+
ensure_future(initialize(), loop=self._loop)
829835

830836
def data_received(self, data):
831837
""" Process data received from Redis server. """
@@ -980,7 +986,7 @@ def _handle_multi_bulk_reply(self, cb):
980986

981987
# Return the empty queue immediately as an answer.
982988
if self._in_pubsub:
983-
asyncio.ensure_future(self._handle_pubsub_multibulk_reply(reply), loop=self._loop)
989+
ensure_future(self._handle_pubsub_multibulk_reply(reply), loop=self._loop)
984990
else:
985991
cb(reply)
986992

0 commit comments

Comments
 (0)
0