Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Add channel_send_wait().
  • Loading branch information
ericsnowcurrently committed May 1, 2020
commit bdc89265099c138cabae9e65c5d0bd5a75a7a741
39 changes: 39 additions & 0 deletions Modules/_xxsubinterpretersmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2577,6 +2577,43 @@ PyDoc_STRVAR(channel_send_doc,
\n\
Add the object's data to the channel's queue.");

static PyObject *
channel_send_wait(PyObject *self, PyObject *args, PyObject *kwds)
{
static char *kwlist[] = {"cid", "obj", NULL};
int64_t cid;
PyObject *obj;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&O:channel_send", kwlist,
channel_id_converter, &cid, &obj)) {
return NULL;
}

_lockobj *lock = _lockobj_new();
if (lock == NULL) {
return NULL;
}
if (_lockobj_acquire(lock) != 0) {
PyErr_SetString(PyExc_RuntimeError, "could not acquire lock");
_lockobj_dealloc(lock);
return NULL;
}
if (_channel_send(&_globals.channels, cid, obj, lock) != 0) {
_lockobj_dealloc(lock);
return NULL;
}
Py_INCREF(lock);
return (PyObject*)lock;
}

PyDoc_STRVAR(channel_send_wait_doc,
"channel_send_wait(cid, obj)\n\
\n\
Add the object's data to the channel's queue.\n\
\n\
The returned callable will block until the object is received.\n\
Note that it takes an optional 'timeout' arg like\n\
threading.Lock.acquire() does.");

static PyObject *
channel_recv(PyObject *self, PyObject *args, PyObject *kwds)
{
Expand Down Expand Up @@ -2729,6 +2766,8 @@ static PyMethodDef module_functions[] = {
METH_VARARGS | METH_KEYWORDS, channel_list_interpreters_doc},
{"channel_send", (PyCFunction)(void(*)(void))channel_send,
METH_VARARGS | METH_KEYWORDS, channel_send_doc},
{"channel_send_wait", (PyCFunction)(void(*)(void))channel_send_wait,
METH_VARARGS | METH_KEYWORDS, channel_send_wait_doc},
{"channel_recv", (PyCFunction)(void(*)(void))channel_recv,
METH_VARARGS | METH_KEYWORDS, channel_recv_doc},
{"channel_close", (PyCFunction)(void(*)(void))channel_close,
Expand Down