I'm completely new to python, but have an async python app using uvloop which uses a C api module I created which also needs access to the async loop.
1) asyncio does not yet have a c-api for this? Any hacks to get an event loop usable in C? Is this being discussed anywhere?
2) uvloop uses libuv which I am familiar with in C. If I can grab the uv_loop_t pointer I could hook into the loop. I assume I can either:
A) With a PyObject * to uvloop's loop calculate the offset to the uv_loop_t* and use that? Assuming I knew the length of PyObject_HEAD?
libuv_loop = (uv_loop_t*)((void*)(loop)+0x8);
struct __pyx_obj_6uvloop_4loop_Loop {
PyObject_HEAD
uv_loop_t *uvloop;
B) Or non hacky modify uvloop to expose the loop pointer. I'm completely clueless here as I've never looked at cython code. Can I create a python function on the loop, call it from my C code and get the C pointer? Like:
(uv_loop_t*)PyObject_CallFunctionObjArgs( getLoop, NULL )
By adding getLoop to here:
https://github.com/MagicStack/uvloop/blob/master/uvloop/loop.pyx
cdef uv.uv_loop_t* _getLoop(self):
return self.uvloop