Skip to content

Commit f638d84

Browse files
authored
Merge branch 'main' into fix-sqs-message-attributes
2 parents f7f4cd2 + ecbb733 commit f638d84

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

kombu/asynchronous/hub.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,10 @@ def close(self, *args):
274274
for item in todos:
275275
item()
276276

277+
# Clear global event loop variable if this hub is the current loop
278+
if _current_loop is self:
279+
set_event_loop(None)
280+
277281
def _discard(self, fd):
278282
fd = fileno(fd)
279283
self.readers.pop(fd, None)

t/unit/asynchronous/test_hub.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,3 +586,30 @@ def test__pop_ready_uses_lock(self):
586586
with patch.object(self.hub, '_ready_lock', autospec=True) as lock:
587587
self.hub._pop_ready()
588588
lock.__enter__.assert_called_once()
589+
590+
def test_close_clears_global_event_loop(self):
591+
# Test that closing a hub clears the global event loop if it's the current one
592+
prev_loop = get_event_loop()
593+
try:
594+
hub = Hub()
595+
set_event_loop(hub)
596+
assert get_event_loop() is hub
597+
hub.close()
598+
assert get_event_loop() is None
599+
finally:
600+
set_event_loop(prev_loop)
601+
602+
def test_close_does_not_clear_other_event_loop(self):
603+
# Test that closing a hub doesn't clear the global event loop if it's a different one
604+
prev_loop = get_event_loop()
605+
try:
606+
hub1 = Hub()
607+
hub2 = Hub()
608+
set_event_loop(hub1)
609+
assert get_event_loop() is hub1
610+
hub2.close()
611+
# hub1 should still be the current loop
612+
assert get_event_loop() is hub1
613+
hub1.close()
614+
finally:
615+
set_event_loop(prev_loop)

0 commit comments

Comments
 (0)