Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Lib/test/test__interpchannels.py
Original file line number Diff line number Diff line change
Expand Up @@ -1208,6 +1208,20 @@ def test_channel_list_interpreters_invalid_args(self):
with self.assertRaises(TypeError):
_channels.list_interpreters(cid)

def test_channel_close_and_list_all(self):
# gh-140652
cid1 = _channels.create(REPLACE)
cid2 = _channels.create(REPLACE)
cid3 = _channels.create(REPLACE)

_channels.close(cid1)
_channels.close(cid2, force=True)

all_channels = [cid for cid, _, _ in _channels.list_all()]
self.assertNotIn(cid1, all_channels)
self.assertNotIn(cid2, all_channels)
self.assertIn(cid3, all_channels)


class ChannelReleaseTests(TestBase):

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix: can not ``list_all`` after ``_interpchannels.close(cid)``
9 changes: 7 additions & 2 deletions Modules/_interpchannelsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1645,13 +1645,18 @@ _channels_list_all(_channels *channels, int64_t *count)
goto done;
}
_channelref *ref = channels->head;
for (int64_t i=0; ref != NULL; ref = ref->next, i++) {
int64_t i = 0;
for (; ref != NULL; ref = ref->next) {
if (ref->chan == NULL) {
continue;
}
ids[i] = (struct channel_id_and_info){
.id = ref->cid,
.defaults = ref->chan->defaults,
};
i++;
}
*count = channels->numopen;
*count = i;

cids = ids;
done:
Expand Down
Loading