8000 bpo-33615: Re-enable subinterpreter tests. (#7552) · python/cpython@ab4a198 · GitHub
[go: up one dir, main page]

Skip to content

Commit ab4a198

Browse files
bpo-33615: Re-enable subinterpreter tests. (#7552)
All the subinterpreter tests were disabled in gh-7513. This commit re-enables them, but leaves one bad test disabled. The test is partly causing problems because it makes assumptions about the availability of a high-level interpreters module (see PEP 554). So I'm disabling the test until such a high-level module is available.
1 parent 71ede00 commit ab4a198

File tree

2 files changed

+51
-42
lines changed

2 files changed

+51
-42
lines changed

Lib/test/test__xxsubinterpreters.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from test import support
1313
from test.support import script_helper
1414

15-
raise unittest.SkipTest("FIXME: bpo-33615: test crash on some CIs")
1615

1716
interpreters = support.import_module('_xxsubinterpreters')
1817

@@ -1317,17 +1316,19 @@ def test_run_string_arg_unresolved(self):
13171316
self.assertEqual(obj, b'spam')
13181317
self.assertEqual(out.strip(), 'send')
13191318

1319+
# XXX For now there is no high-level channel into which the
1320+
# sent channel ID can be converted...
1321+
# Note: this test caused crashes on some buildbots (bpo-33615).
1322+
@unittest.skip('disabled until high-level channels exist')
13201323
def test_run_string_arg_resolved(self):
13211324
cid = interpreters.channel_create()
13221325
cid = interpreters._channel_id(cid, _resolve=True)
13231326
interp = interpreters.create()
13241327

13251328
out = _run_output(interp, dedent("""
13261329
import _xxsubinterpreters as _interpreters
1327-
print(chan.end)
1328-
_interpreters.channel_send(chan, b'spam')
1329-
#print(chan.id.end)
1330-
#_interpreters.channel_send(chan.id, b'spam')
1330+
print(chan.id.end)
1331+
_interpreters.channel_send(chan.id, b'spam')
13311332
"""),
13321333
dict(chan=cid.send))
13331334
obj = interpreters.channel_recv(cid)

Modules/_xxsubinterpretersmodule.c

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,11 +1000,11 @@ _channels_lookup(_channels *channels, int64_t id, PyThread_type_lock *pmutex)
10001000

10011001
_channelref *ref = _channelref_find(channels->head, id, NULL);
10021002
if (ref == NULL) {
1003-
PyErr_Format(ChannelNotFoundError, "channel %lld not found", id);
1003+
PyErr_Format(ChannelNotFoundError, "channel %" PRId64 " not found", id);
10041004
goto done;
10051005
}
10061006
if (ref->chan == NULL || !ref->chan->open) {
1007-
PyErr_Format(ChannelClosedError, "channel %lld closed", id);
1007+
PyErr_Format(ChannelClosedError, "channel %" PRId64 " closed", id);
10081008
goto done;
10091009
}
10101010

@@ -1064,16 +1064,16 @@ _channels_close(_channels *channels, int64_t cid, _PyChannelState **pchan,
10641064

10651065
_channelref *ref = _channelref_find(channels->head, cid, NULL);
10661066
if (ref == NULL) {
1067-
PyErr_Format(ChannelNotFoundError, "channel %lld not found", cid);
1067+
PyErr_Format(ChannelNotFoundError, "channel %" PRId64 " not found", cid);
10681068
goto done;
10691069
}
10701070

10711071
if (ref->chan == NULL) {
1072-
PyErr_Format(ChannelClosedError, "channel %lld closed", cid);
1072+
PyErr_Format(ChannelClosedError, "channel %" PRId64 " closed", cid);
10731073
goto done;
10741074
}
10751075
else if (!force && end == CHANNEL_SEND && ref->chan->closing != NULL) {
1076-
PyErr_Format(ChannelClosedError, "channel %lld closed", cid);
1076+
PyErr_Format(ChannelClosedError, "channel %" PRId64 " closed", cid);
10771077
goto done;
10781078
}
10791079
else {
@@ -1082,7 +1082,7 @@ _channels_close(_channels *channels, int64_t cid, _PyChannelState **pchan,
10821082
PyErr_ExceptionMatches(ChannelNotEmptyError)) {
10831083
if (ref->chan->closing != NULL) {
10841084
PyErr_Format(ChannelClosedError,
1085-
"channel %lld closed", cid);
1085+
"channel %" PRId64 " closed", cid);
10861086
goto done;
10871087
}
10881088
// Mark the channel as closing and return. The channel
@@ -1144,7 +1144,7 @@ _channels_remove(_channels *channels, int64_t id, _PyChannelState **pchan)
11441144
_channelref *prev = NULL;
11451145
_channelref *ref = _channelref_find(channels->head, id, &prev);
11461146
if (ref == NULL) {
1147-
PyErr_Format(ChannelNotFoundError, "channel %lld not found", id);
1147+
PyErr_Format(ChannelNotFoundError, "channel %" PRId64 " not found", id);
11481148
goto done;
11491149
}
11501150

@@ -1164,7 +1164,7 @@ _channels_add_id_object(_channels *channels, int64_t id)
11641164

11651165
_channelref *ref = _channelref_find(channels->head, id, NULL);
11661166
if (ref == NULL) {
1167-
PyErr_Format(ChannelNotFoundError, "channel %lld not found", id);
1167+
PyErr_Format(ChannelNotFoundError, "channel %" PRId64 " not found", id);
11681168
goto done;
11691169
}
11701170
ref->objcount += 1;
@@ -1328,7 +1328,7 @@ _channel_send(_channels *channels, int64_t id, PyObject *obj)
13281328
// Past this point we are responsible for releasing the mutex.
13291329

13301330
if (chan->closing != NULL) {
1331-
PyErr_Format(ChannelClosedError, "channel %lld closed", id);
1331+
PyErr_Format(ChannelClosedError, "channel %" PRId64 " closed", id);
13321332
PyThread_release_lock(mutex);
13331333
return -1;
13341334
}
@@ -1377,7 +1377,7 @@ _channel_recv(_channels *channels, int64_t id)
13771377
PyThread_release_lock(mutex);
13781378
if (data == NULL) {
13791379
if (!PyErr_Occurred()) {
1380-
PyErr_Format(ChannelEmptyError, "channel %lld is empty", id);
1380+
PyErr_Format(ChannelEmptyError, "channel %" PRId64 " is empty", id);
13811381
}
13821382
return NULL;
13831383
}
@@ -1527,13 +1527,13 @@ channelid_repr(PyObject *self)
15271527
channelid *cid = (channelid *)self;
15281528
const char *fmt;
15291529
if (cid->end == CHANNEL_SEND) {
1530-
fmt = "%s(%lld, send=True)";
1530+
fmt = "%s(%" PRId64 ", send=True)";
15311531
}
15321532
else if (cid->end == CHANNEL_RECV) {
1533-
fmt = "%s(%lld, recv=True)";
1533+
fmt = "%s(%" PRId64 ", recv=True)";
15341534
}
15351535
else {
1536-
fmt = "%s(%lld)";
1536+
fmt = "%s(%" PRId64 ")";
15371537
}
15381538
return PyUnicode_FromFormat(fmt, name, cid->id);
15391539
}
@@ -1542,7 +1542,7 @@ static PyObject *
15421542
channelid_str(PyObject *self)
15431543
{
15441544
channelid *cid = (channelid *)self;
1545-
return PyUnicode_FromFormat("%lld", cid->id);
1545+
return PyUnicode_FromFormat("%" PRId64 "", cid->id);
15461546
}
15471547

15481548
PyObject *
@@ -1652,6 +1652,32 @@ channelid_richcompare(PyObject *self, PyObject *other, int op)
16521652
Py_RETURN_FALSE;
16531653
}
16541654

1655+
static PyObject *
1656+
_channel_from_cid(PyObject *cid, int end)
1657+
{
1658+
PyObject *highlevel = PyImport_ImportModule("interpreters");
1659+
if (highlevel == NULL) {
1660+
PyErr_Clear();
1661+
highlevel = PyImport_ImportModule("test.support.interpreters");
1662+
if (highlevel == NULL) {
1663+
return NULL;
1664+
}
1665+
}
1666+
const char *clsname = (end == CHANNEL_RECV) ? "RecvChannel" :
1667+
"SendChannel";
1668+
PyObject *cls = PyObject_GetAttrString(highlevel, clsname);
1669+
Py_DECREF(highlevel);
1670+
if (cls == NULL) {
1671+
return NULL;
1672+
}
1673+
PyObject *chan = PyObject_CallFunctionObjArgs(cls, cid, NULL);
1674+
Py_DECREF(cls);
1675+
if (chan == NULL) {
1676+
return NULL;
1677+
}
1678+
return chan;
1679+
}
1680+
16551681
struct _channelid_xid {
16561682
int64_t id;
16571683
int end;
@@ -1673,31 +1699,13 @@ _channelid_from_xid(_PyCrossInterpreterData *data)
16731699
}
16741700

16751701
/* Try returning a high-level channel end but fall back to the ID. */
1676-
PyObject *highlevel = PyImport_ImportModule("interpreters");
1677-
if (highlevel == NULL) {
1678-
PyErr_Clear();
1679-
highlevel = PyImport_ImportModule("test.support.interpreters");
1680-
if (highlevel == NULL) {
1681-
goto error;
1682-
}
1683-
}
1684-
const char *clsname = (xid->end == CHANNEL_RECV) ? "RecvChannel" :
1685-
"SendChannel";
1686-
PyObject *cls = PyObject_GetAttrString(highlevel, clsname);
1687-
Py_DECREF(highlevel);
1688-
if (cls == NULL) {
1689-
goto error;
1690-
}
1691-
PyObject *chan = PyObject_CallFunctionObjArgs(cls, cid, NULL);
1702+
PyObject *chan = _channel_from_cid(cid, xid->end);
16921703
if (chan == NULL) {
1693-
goto error;
1704+
PyErr_Clear();
1705+
return cid;
16941706
}
16951707
Py_DECREF(cid);
16961708
return chan;
1697-
1698-
error:
1699-
PyErr_Clear();
1700-
return cid;
17011709
}
17021710

17031711
static int
@@ -2048,14 +2056,14 @@ interpid_repr(PyObject *self)
20482056
PyTypeObject *type = Py_TYPE(self);
20492057
const char *name = _PyType_Name(type);
20502058
interpid *id = (interpid *)self;
2051-
return PyUnicode_FromFormat("%s(%lld)", name, id->id);
2059+
return PyUnicode_FromFormat("%s(%" PRId64 ")", name, id->id);
20522060
}
20532061

20542062
static PyObject *
20552063
interpid_str(PyObject *self)
20562064
{
20572065
interpid *id = (interpid *)self;
2058-
return PyUnicode_FromFormat("%lld", id->id);
2066+
return PyUnicode_FromFormat("%" PRId64 "", id->id);
20592067
}
20602068

20612069
PyObject *

0 commit comments

Comments
 (0)
0