WebSocket-for-Python icon indicating copy to clipboard operation
WebSocket-for-Python copied to clipboard

How to add other file descriptors to the main loop?

Open jrief opened this issue 12 years ago • 1 comments

Currently I am working on a server based on the code for WebSocketWSGIApplication in geventserver.py.

There, I wanted to add some code to this server to be informed when someone publishes a message through a Redis channel. This event is signaled through a file descriptor, which is a member of that channel class. If I would own the main loop, this would be easy, since I could add this Redis fd to the list passed to the select.select call, and wait if either the websocket's fd or the Redis fd signals that some data is ready for reading. However, since I can not access the main loop, I wanted to ask how to add foreign file descriptors to the select call in the main loop.

jrief avatar Dec 05 '13 23:12 jrief

Hi there,

That is a good question to a use case I hadn't considered. I think, initially the manager was there to mutualize and rationalize the process life of a websocket. It might not be the right response on the long run, I mean from an implementation's perspective.

As of now, it's not a general purpose loop such as tornado or asyncio can provide, and it's really specialized in dealing with ws4py WebSocket objects. There are options such as moving to one of those loop provider but I'm afraid they would be a rather high dependency (I mean if you're going to use the tornado's loop, you might as well simply use tornado itself).

I'm not sure how to address this question.

Lawouach avatar Dec 06 '13 11:12 Lawouach