@@ -2098,6 +2098,11 @@ struct channel_info {
2098
2098
struct {
2099
2099
// 1: closed; -1: closing
2100
2100
int closed ;
2101
+ struct {
2102
+ // 1: associated; -1: released
2103
+ int send ;
2104
+ int recv ;
2105
+ } cur ;
2101
2106
} status ;
2102
2107
Py_ssize_t count ;
2103
2108
};
@@ -2108,6 +2113,13 @@ _channel_get_info(_channels *channels, int64_t cid, struct channel_info *info)
2108
2113
int err = 0 ;
2109
2114
* info = (struct channel_info ){0 };
2110
2115
2116
+ // Get the current interpreter.
2117
+ PyInterpreterState * interp = _get_current_interp ();
2118
+ if (interp == NULL ) {
2119
+ return -1 ;
2120
+ }
2121
+ Py_ssize_t interpid = PyInterpreterState_GetID (interp );
2122
+
2111
2123
// Hold the global lock until we're done.
2112
2124
PyThread_acquire_lock (channels -> mutex , WAIT_LOCK );
2113
2125
@@ -2140,6 +2152,22 @@ _channel_get_info(_channels *channels, int64_t cid, struct channel_info *info)
2140
2152
// Get the number of queued objects.
2141
2153
info -> count = chan -> queue -> count ;
2142
2154
2155
+ // Get the current ends status.
2156
+ _channelend * send = _channelend_find (chan -> ends -> send , interpid , NULL );
2157
+ if (send == NULL ) {
2158
+ info -> status .cur .send = 0 ;
2159
+ }
2160
+ else {
2161
+ info -> status .cur .send = send -> open ? 1 : -1 ;
2162
+ }
2163
+ _channelend * recv = _channelend_find (chan -> ends -> recv , interpid , NULL );
2164
+ if (recv == NULL ) {
2165
+ info -> status .cur .recv = 0 ;
2166
+ }
2167
+ else {
2168
+ info -> status .cur .recv = recv -> open ? 1 : -1 ;
2169
+ }
2170
+
2143
2171
finally :
2144
2172
PyThread_release_lock (channels -> mutex );
2145
2173
return err ;
@@ -2155,14 +2183,18 @@ static PyStructSequence_Field channel_info_fields[] = {
2155
2183
{"closing" , "send is closed, recv is non-empty" },
2156
2184
{"closed" , "both ends are closed" },
2157
2185
{"count" , "queued objects" },
2186
+ {"send_associated" , "current interpreter is bound to the send end" },
2187
+ {"send_released" , "current interpreter *was* bound to the send end" },
2188
+ {"recv_associated" , "current interpreter is bound to the recv end" },
2189
+ {"recv_released" , "current interpreter *was* bound to the recv end" },
2158
2190
{0 }
2159
2191
};
2160
2192
2161
2193
static PyStructSequence_Desc channel_info_desc = {
2162
2194
.name = "ChannelInfo" ,
2163
2195
.doc = channel_info_doc ,
2164
2196
.fields = channel_info_fields ,
2165
- .n_in_sequence = 4 ,
2197
+ .n_in_sequence = 8 ,
2166
2198
};
2167
2199
2168
2200
static PyObject *
@@ -2196,6 +2228,10 @@ new_channel_info(PyObject *mod, struct channel_info *info)
2196
2228
SET_BOOL (info -> status .closed == -1 );
2197
2229
SET_BOOL (info -> status .closed == 1 );
2198
2230
SET_COUNT (info -> count );
2231
+ SET_BOOL (info -> status .cur .send == 1 );
2232
+ SET_BOOL (info -> status .cur .send == -1 );
2233
+ SET_BOOL (info -> status .cur .recv == 1 );
2234
+ SET_BOOL (info -> status .cur .recv == -1 );
2199
2235
#undef SET_COUNT
2200
2236
#undef SET_BOOL
2201
2237
assert (!PyErr_Occurred ());
0 commit comments