File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -302,7 +302,10 @@ async def flush(self):
302
302
pass
303
303
self ._receive_task = None
304
304
if self ._redis is not None :
305
- await self ._redis .close ()
305
+ # The pool was created just for this client, so make sure it is closed,
306
+ # otherwise it will schedule the connection to be closed inside the
307
+ # __del__ method, which doesn't have a loop running anymore.
308
+ await self ._redis .close (close_connection_pool = True )
306
309
self ._redis = None
307
310
self ._pubsub = None
308
311
self ._subscribed_to = set ()
Original file line number Diff line number Diff line change @@ -32,6 +32,21 @@ async def other_channel_layer():
32
32
await channel_layer .flush ()
33
33
34
34
35
+ def test_layer_close ():
36
+ """
37
+ If the channel layer does not close properly there will be a "Task was destroyed but it is pending!" warning at
38
+ process exit.
39
+ """
40
+
41
+ async def do_something_with_layer ():
42
+ channel_layer = RedisPubSubChannelLayer (hosts = TEST_HOSTS )
43
+ await channel_layer .send (
44
+ "TestChannel" , {"type" : "test.message" , "text" : "Ahoy-hoy!" }
45
+ )
46
+
47
+ async_to_sync (do_something_with_layer )()
48
+
49
+
35
50
@pytest .mark .asyncio
36
51
async def test_send_receive (channel_layer ):
37
52
"""
You can’t perform that action at this time.
0 commit comments