mirror of
https://github.com/jorisvink/kore
synced 2025-03-09 04:29:02 -04:00
Python coro under-the-hood improvements.
- Change python coroutine id to a uint64_t. - Add kore.task_id() to return active coro its id.
This commit is contained in:
parent
86ecb85f03
commit
5ac62b17bc
@ -18,7 +18,7 @@
|
||||
#define CORO_STATE_SUSPENDED 2
|
||||
|
||||
struct python_coro {
|
||||
u_int32_t id;
|
||||
u_int64_t id;
|
||||
int state;
|
||||
int killed;
|
||||
PyObject *obj;
|
||||
@ -45,6 +45,7 @@ static PyObject *python_kore_queue(PyObject *, PyObject *);
|
||||
static PyObject *python_kore_worker(PyObject *, PyObject *);
|
||||
static PyObject *python_kore_tracer(PyObject *, PyObject *);
|
||||
static PyObject *python_kore_fatalx(PyObject *, PyObject *);
|
||||
static PyObject *python_kore_task_id(PyObject *, PyObject *);
|
||||
static PyObject *python_kore_setname(PyObject *, PyObject *);
|
||||
static PyObject *python_kore_suspend(PyObject *, PyObject *);
|
||||
static PyObject *python_kore_shutdown(PyObject *, PyObject *);
|
||||
@ -96,6 +97,7 @@ static struct PyMethodDef pykore_methods[] = {
|
||||
METHOD("tracer", python_kore_tracer, METH_VARARGS),
|
||||
METHOD("fatal", python_kore_fatal, METH_VARARGS),
|
||||
METHOD("fatalx", python_kore_fatalx, METH_VARARGS),
|
||||
METHOD("task_id", python_kore_task_id, METH_NOARGS),
|
||||
METHOD("setname", python_kore_setname, METH_VARARGS),
|
||||
METHOD("suspend", python_kore_suspend, METH_VARARGS),
|
||||
METHOD("shutdown", python_kore_shutdown, METH_NOARGS),
|
||||
|
21
src/python.c
21
src/python.c
@ -24,6 +24,7 @@
|
||||
|
||||
#include <ctype.h>
|
||||
#include <libgen.h>
|
||||
#include <inttypes.h>
|
||||
#include <signal.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
@ -1173,7 +1174,7 @@ python_coro_trace(const char *label, struct python_coro *coro)
|
||||
kore_log(LOG_NOTICE, "coro '%s' %s <%s> @ [%s:%d]",
|
||||
coro->name, label, func, fname, line);
|
||||
} else {
|
||||
kore_log(LOG_NOTICE, "coro %u %s <%s> @ [%s:%d]",
|
||||
kore_log(LOG_NOTICE, "coro %" PRIu64 " %s <%s> @ [%s:%d]",
|
||||
coro->id, label, func, fname, line);
|
||||
}
|
||||
}
|
||||
@ -1945,16 +1946,28 @@ python_kore_task_create(PyObject *self, PyObject *args)
|
||||
coro = python_coro_create(obj, NULL);
|
||||
Py_INCREF(obj);
|
||||
|
||||
return (PyLong_FromUnsignedLong(coro->id));
|
||||
return (PyLong_FromUnsignedLongLong(coro->id));
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
python_kore_task_id(PyObject *self, PyObject *args)
|
||||
{
|
||||
if (coro_running == NULL) {
|
||||
PyErr_SetString(PyExc_RuntimeError,
|
||||
"no coroutine active");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
return (PyLong_FromUnsignedLongLong(coro_running->id));
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
python_kore_task_kill(PyObject *self, PyObject *args)
|
||||
{
|
||||
u_int32_t id;
|
||||
u_int64_t id;
|
||||
struct python_coro *coro, *active;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "I", &id))
|
||||
if (!PyArg_ParseTuple(args, "K", &id))
|
||||
return (NULL);
|
||||
|
||||
if (coro_running != NULL && coro_running->id == id) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user