uvloop icon indicating copy to clipboard operation
uvloop copied to clipboard

How to share libuv between multiple libraries

Open iceboy233 opened this issue 9 years ago • 8 comments

If there are other C libraries using libuv and expose python interface, is there a way to use the same uv event loop for uvloop and the library?

iceboy233 avatar Sep 02 '16 15:09 iceboy233

To achieve it uvloop should only expose uv_loop_t instance, isn't it?

asvetlov avatar Sep 03 '16 17:09 asvetlov

What's the use case?

1st1 avatar Sep 03 '16 19:09 1st1

I'm playing with a HTTP server called h2o which supports to be used as a library and I'm trying to make a python binding for it (just for fun now - if it could be done, we can get a super high performance HTTP server). The server supports its own event loop and also uv loop. It'll be nice if we could make python bindings of these kind of libraries which share a single event loop.

iceboy233 avatar Sep 04 '16 12:09 iceboy233

Interesting. Well, in theory we could provide some API for that, but somebody will have to pioneer and submit a PR with an example use case code.

1st1 avatar Sep 05 '16 22:09 1st1

@iceb0y Are you still working on this? I could probably expose a semi-public ctypes Ptr to the libuv event loop.

1st1 avatar Oct 21 '16 20:10 1st1

Well, I'll need that too, I am writing a portable messaging library chirp connecting the major platforms (python, node, ruby... etc and C of course). The most efficient way to write bindings is uvloop and chirp sharing uv_loop_t. It shouldn't be too difficult to grab the pointer somewhere. It will take some time till I am writing the bindings... if there is no API for this till then, I'l do the PR.

rhizoome avatar Apr 20 '17 14:04 rhizoome

I have a server that sets up uvloop in python then runs in C. To access the loop I call out to python. It would be nice to have access to the uv_loop_t to attach say this redis C client to the loop using the following code.

https://github.com/redis/hiredis/blob/master/adapters/libuv.h

MarkReedZ avatar Apr 11 '18 01:04 MarkReedZ

Exposing the loop may not be a good idea as I believe I see uvloop and other libraries using the loop's data field. It would at least need a note. Locally I've exposed the loop by adding a function that returns it as a PyLong and am using it.

MarkReedZ avatar Apr 13 '18 22:04 MarkReedZ

Fixed in #310

fantix avatar Sep 09 '22 14:09 fantix