Skip to content

Commit e67d15c

Browse files
authored
replase get_event_loop wite get_running_loop (#2530)
1 parent f14ed1f commit e67d15c

File tree

6 files changed

+20
-20
lines changed

6 files changed

+20
-20
lines changed

redis/asyncio/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ def __del__(self, _warnings: Any = warnings) -> None:
453453
f"Unclosed client session {self!r}", ResourceWarning, source=self
454454
)
455455
context = {"client": self, "message": self._DEL_MESSAGE}
456-
asyncio.get_event_loop().call_exception_handler(context)
456+
asyncio.get_running_loop().call_exception_handler(context)
457457

458458
async def close(self, close_connection_pool: Optional[bool] = None) -> None:
459459
"""
@@ -798,7 +798,7 @@ async def check_health(self):
798798

799799
if (
800800
conn.health_check_interval
801-
and asyncio.get_event_loop().time() > conn.next_health_check
801+
and asyncio.get_running_loop().time() > conn.next_health_check
802802
):
803803
await conn.send_command(
804804
"PING", self.HEALTH_CHECK_MESSAGE, check_health=False

redis/asyncio/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ def repr_pieces(self):
532532
def __del__(self):
533533
try:
534534
if self.is_connected:
535-
loop = asyncio.get_event_loop()
535+
loop = asyncio.get_running_loop()
536536
coro = self.disconnect()
537537
if loop.is_running():
538538
loop.create_task(coro)

redis/asyncio/lock.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,14 @@ async def acquire(
201201
blocking_timeout = self.blocking_timeout
202202
stop_trying_at = None
203203
if blocking_timeout is not None:
204-
stop_trying_at = asyncio.get_event_loop().time() + blocking_timeout
204+
stop_trying_at = asyncio.get_running_loop().time() + blocking_timeout
205205
while True:
206206
if await self.do_acquire(token):
207207
self.local.token = token
208208
return True
209209
if not blocking:
210210
return False
211-
next_try_at = asyncio.get_event_loop().time() + sleep
211+
next_try_at = asyncio.get_running_loop().time() + sleep
212212
if stop_trying_at is not None and next_try_at > stop_trying_at:
213213
return False
214214
await asyncio.sleep(sleep)

tests/test_asyncio/test_connection_pool.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,11 @@ async def test_connection_pool_blocks_until_timeout(self, master_host):
243243
) as pool:
244244
c1 = await pool.get_connection("_")
245245

246-
start = asyncio.get_event_loop().time()
246+
start = asyncio.get_running_loop().time()
247247
with pytest.raises(redis.ConnectionError):
248248
await pool.get_connection("_")
249249
# we should have waited at least 0.1 seconds
250-
assert asyncio.get_event_loop().time() - start >= 0.1
250+
assert asyncio.get_running_loop().time() - start >= 0.1
251251
await c1.disconnect()
252252

253253
async def test_connection_pool_blocks_until_conn_available(self, master_host):
@@ -265,9 +265,9 @@ async def target():
265265
await asyncio.sleep(0.1)
266266
await pool.release(c1)
267267

268-
start = asyncio.get_event_loop().time()
268+
start = asyncio.get_running_loop().time()
269269
await asyncio.gather(target(), pool.get_connection("_"))
270-
assert asyncio.get_event_loop().time() - start >= 0.1
270+
assert asyncio.get_running_loop().time() - start >= 0.1
271271

272272
async def test_reuse_previously_released_connection(self, master_host):
273273
connection_kwargs = {"host": master_host}
@@ -668,20 +668,20 @@ async def r(self, create_redis):
668668
await redis.flushall()
669669

670670
def assert_interval_advanced(self, connection):
671-
diff = connection.next_health_check - asyncio.get_event_loop().time()
671+
diff = connection.next_health_check - asyncio.get_running_loop().time()
672672
assert self.interval >= diff > (self.interval - 1)
673673

674674
async def test_health_check_runs(self, r):
675675
if r.connection:
676-
r.connection.next_health_check = asyncio.get_event_loop().time() - 1
676+
r.connection.next_health_check = asyncio.get_running_loop().time() - 1
677677
await r.connection.check_health()
678678
self.assert_interval_advanced(r.connection)
679679

680680
async def test_arbitrary_command_invokes_health_check(self, r):
681681
# invoke a command to make sure the connection is entirely setup
682682
if r.connection:
683683
await r.get("foo")
684-
r.connection.next_health_check = asyncio.get_event_loop().time()
684+
r.connection.next_health_check = asyncio.get_running_loop().time()
685685
with mock.patch.object(
686686
r.connection, "send_command", wraps=r.connection.send_command
687687
) as m:

tests/test_asyncio/test_lock.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ async def test_high_sleep_small_blocking_timeout(self, r):
136136
sleep = 60
137137
bt = 1
138138
lock2 = self.get_lock(r, "foo", sleep=sleep, blocking_timeout=bt)
139-
start = asyncio.get_event_loop().time()
139+
start = asyncio.get_running_loop().time()
140140
assert not await lock2.acquire()
141141
# the elapsed timed is less than the blocking_timeout as the lock is
142142
# unattainable given the sleep/blocking_timeout configuration
143-
assert bt > (asyncio.get_event_loop().time() - start)
143+
assert bt > (asyncio.get_running_loop().time() - start)
144144
await lock1.release()
145145

146146
async def test_releasing_unlocked_lock_raises_error(self, r):

tests/test_asyncio/test_pubsub.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ async def run(*args, **kwargs):
3030

3131

3232
async def wait_for_message(pubsub, timeout=0.2, ignore_subscribe_messages=False):
33-
now = asyncio.get_event_loop().time()
33+
now = asyncio.get_running_loop().time()
3434
timeout = now + timeout
3535
while now < timeout:
3636
message = await pubsub.get_message(
@@ -39,7 +39,7 @@ async def wait_for_message(pubsub, timeout=0.2, ignore_subscribe_messages=False)
3939
if message is not None:
4040
return message
4141
await asyncio.sleep(0.01)
42-
now = asyncio.get_event_loop().time()
42+
now = asyncio.get_running_loop().time()
4343
return None
4444

4545

@@ -675,7 +675,7 @@ async def loop_step():
675675
await messages.put(message)
676676
break
677677

678-
task = asyncio.get_event_loop().create_task(loop())
678+
task = asyncio.get_running_loop().create_task(loop())
679679
# get the initial connect message
680680
async with async_timeout.timeout(1):
681681
message = await messages.get()
@@ -724,7 +724,7 @@ def callback(message):
724724
messages = asyncio.Queue()
725725
p = pubsub
726726
await self._subscribe(p, foo=callback)
727-
task = asyncio.get_event_loop().create_task(p.run())
727+
task = asyncio.get_running_loop().create_task(p.run())
728728
await r.publish("foo", "bar")
729729
message = await messages.get()
730730
task.cancel()
@@ -748,7 +748,7 @@ def exception_handler_callback(e, pubsub) -> None:
748748
p = pubsub
749749
await self._subscribe(p, foo=lambda x: None)
750750
with mock.patch.object(p, "get_message", side_effect=Exception("error")):
751-
task = asyncio.get_event_loop().create_task(
751+
task = asyncio.get_running_loop().create_task(
752752
p.run(exception_handler=exception_handler_callback)
753753
)
754754
e = await exceptions.get()
@@ -765,7 +765,7 @@ def callback(message):
765765

766766
messages = asyncio.Queue()
767767
p = pubsub
768-
task = asyncio.get_event_loop().create_task(p.run())
768+
task = asyncio.get_running_loop().create_task(p.run())
769769
# wait until loop gets settled. Add a subscription
770770
await asyncio.sleep(0.1)
771771
await p.subscribe(foo=callback)

0 commit comments

Comments
 (0)