Skip to content

Commit 688c38f

Browse files
committed
fix: can not list_all after _interpchannels.close
Signed-off-by: yihong0618 <[email protected]>
1 parent 3dab11f commit 688c38f

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

Lib/test/test__interpchannels.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,20 @@ def test_channel_list_interpreters_invalid_args(self):
12081208
with self.assertRaises(TypeError):
12091209
_channels.list_interpreters(cid)
12101210

1211+
def test_channel_close_and_list_all(self):
1212+
# gh-140652
1213+
cid1 = _channels.create(REPLACE)
1214+
cid2 = _channels.create(REPLACE)
1215+
cid3 = _channels.create(REPLACE)
1216+
1217+
_channels.close(cid1)
1218+
_channels.close(cid2, force=True)
1219+
1220+
all_channels = [cid for cid, _, _ in _channels.list_all()]
1221+
self.assertNotIn(cid1, all_channels)
1222+
self.assertNotIn(cid2, all_channels)
1223+
self.assertIn(cid3, all_channels)
1224+
12111225

12121226
class ChannelReleaseTests(TestBase):
12131227

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix: can not ``list_all`` after ``_interpchannels.close(cid)``

Modules/_interpchannelsmodule.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,13 +1645,18 @@ _channels_list_all(_channels *channels, int64_t *count)
16451645
goto done;
16461646
}
16471647
_channelref *ref = channels->head;
1648-
for (int64_t i=0; ref != NULL; ref = ref->next, i++) {
1648+
int64_t i = 0;
1649+
for (; ref != NULL; ref = ref->next) {
1650+
if (ref->chan == NULL) {
1651+
continue;
1652+
}
16491653
ids[i] = (struct channel_id_and_info){
16501654
.id = ref->cid,
16511655
.defaults = ref->chan->defaults,
16521656
};
1657+
i++;
16531658
}
1654-
*count = channels->numopen;
1659+
*count = i;
16551660

16561661
cids = ids;
16571662
done:

0 commit comments

Comments
 (0)