54
54
START_REDIS_SERVER = bool (os .environ .get ('START_REDIS_SERVER' , False ))
55
55
56
56
57
+ # In Python 3.4.4, `async` was renamed to `ensure_future`.
58
+ try :
59
+ ensure_future = asyncio .ensure_future
60
+ except AttributeError :
61
+ ensure_future = asyncio .async
62
+
63
+
57
64
@asyncio .coroutine
58
65
def connect (loop , protocol = RedisProtocol ):
59
66
""" Connect to redis server. Return transport/protocol pair. """
@@ -564,7 +571,7 @@ def blpop():
564
571
self .assertEqual (value .list_name , u'my_list' )
565
572
self .assertEqual (value .value , u'value' )
566
573
test_order .append ('#3' )
567
- f = asyncio . async (blpop (), loop = self .loop )
574
+ f = ensure_future (blpop (), loop = self .loop )
568
575
569
576
transport2 , protocol2 = yield from connect (self .loop )
570
577
@@ -580,7 +587,7 @@ def blpop():
580
587
self .assertIsInstance (value , BlockingPopReply )
581
588
self .assertEqual (value .list_name , u'my_list' )
582
589
self .assertEqual (value .value , u'value2' )
583
- f = asyncio . async (blpop (), loop = self .loop )
590
+ f = ensure_future (blpop (), loop = self .loop )
584
591
585
592
yield from protocol2 .rpush (u'my_list' , [u'value2' ])
586
593
yield from f
@@ -597,7 +604,7 @@ def test_brpoplpush(self, transport, protocol):
597
604
def brpoplpush ():
598
605
result = yield from protocol .brpoplpush (u'from' , u'to' )
599
606
self .assertEqual (result , u'my_value' )
600
- f = asyncio . async (brpoplpush (), loop = self .loop )
607
+ f = ensure_future (brpoplpush (), loop = self .loop )
601
608
602
609
transport2 , protocol2 = yield from connect (self .loop )
603
610
yield from protocol2 .rpush (u'from' , [u'my_value' ])
@@ -838,7 +845,7 @@ def listener():
838
845
839
846
return transport2
840
847
841
- f = asyncio . async (listener (), loop = self .loop )
848
+ f = ensure_future (listener (), loop = self .loop )
842
849
843
850
@asyncio .coroutine
844
851
def sender ():
@@ -906,7 +913,7 @@ def listener():
906
913
907
914
transport2 .close ()
908
915
909
- f = asyncio . async (listener (), loop = self .loop )
916
+ f = ensure_future (listener (), loop = self .loop )
910
917
911
918
@asyncio .coroutine
912
919
def sender ():
@@ -948,7 +955,7 @@ def listener():
948
955
949
956
transport2 .close ()
950
957
951
- f = asyncio . async (listener (), loop = self .loop )
958
+ f = ensure_future (listener (), loop = self .loop )
952
959
953
960
@asyncio .coroutine
954
961
def sender ():
@@ -1441,7 +1448,7 @@ def run_while_true():
1441
1448
transport .close ()
1442
1449
1443
1450
# (start script)
1444
- f = asyncio . async (run_while_true (), loop = self .loop )
1451
+ f = ensure_future (run_while_true (), loop = self .loop )
1445
1452
yield from asyncio .sleep (.5 , loop = self .loop )
1446
1453
1447
1454
result = yield from protocol .script_kill ()
@@ -1773,7 +1780,7 @@ def test_cancellation(self, transport, protocol):
1773
1780
@asyncio .coroutine
1774
1781
def run ():
1775
1782
yield from protocol .brpop (['key' ], 3 )
1776
- f = asyncio . async (run (), loop = self .loop )
1783
+ f = ensure_future (run (), loop = self .loop )
1777
1784
1778
1785
# We cancel the coroutine before the answer arrives.
1779
1786
yield from asyncio .sleep (.5 , loop = self .loop )
@@ -1900,7 +1907,7 @@ def listener():
1900
1907
def sender ():
1901
1908
value = yield from protocol .publish (b'our_channel' , b'message1' )
1902
1909
1903
- f = asyncio . async (listener (), loop = self .loop )
1910
+ f = ensure_future (listener (), loop = self .loop )
1904
1911
yield from asyncio .sleep (.5 , loop = self .loop )
1905
1912
yield from sender ()
1906
1913
transport2 = yield from f
@@ -1992,7 +1999,7 @@ def test():
1992
1999
1993
2000
# Wait for ever. (This blocking pop doesn't return.)
1994
2001
yield from connection .delete ([ 'unknown-key' ])
1995
- f = asyncio . async (connection .blpop (['unknown-key' ]), loop = self .loop )
2002
+ f = ensure_future (connection .blpop (['unknown-key' ]), loop = self .loop )
1996
2003
yield from asyncio .sleep (.1 , loop = self .loop ) # Sleep to make sure that the above coroutine started executing.
1997
2004
1998
2005
# Run command in other thread.
@@ -2040,8 +2047,8 @@ def source():
2040
2047
yield from asyncio .sleep (.5 , loop = self .loop )
2041
2048
2042
2049
# Run both coroutines.
2043
- f1 = asyncio . async (source (), loop = self .loop )
2044
- f2 = asyncio . async (sink (), loop = self .loop )
2050
+ f1 = ensure_future (source (), loop = self .loop )
2051
+ f2 = ensure_future (sink (), loop = self .loop )
2045
2052
yield from gather (f1 , f2 )
2046
2053
2047
2054
# Test results.
@@ -2095,7 +2102,7 @@ def sink(i):
2095
2102
futures = []
2096
2103
for i in range (0 , 10 ):
2097
2104
self .assertEqual (connection .connections_in_use , i )
2098
- futures .append (asyncio . async (sink (i ), loop = self .loop ))
2105
+ futures .append (ensure_future (sink (i ), loop = self .loop ))
2099
2106
yield from asyncio .sleep (.1 , loop = self .loop ) # Sleep to make sure that the above coroutine started executing.
2100
2107
2101
2108
# One more blocking call should fail.
0 commit comments