How to replace select() with epoll() in python?

Viewed 838

I'm programming python web socket chat server. I made working server using function select() to listen to clients, but when I connect more than 512 clients on Windows or 1024 clients on Linux, my server crashes. After research I found that this is system limit and I need to use poll() or epoll() for more connections.

This is part of code using select() that I need to rewrite using epoll() or poll() function:

from select import select
rList, wList, xList = select(listeners, writers, listeners, interval)
for ready in wList:
    function1()
for ready in rList:
    function2()
for failed in xList:
    function3()

How can I do the same thing using epoll() or poll()? It still needs to call these functions above.

1 Answers

I believe it should be

rList, wList, xList = select.select(listeners, writers, listeners, interval)

you can change it to

poll = select.poll()
poll.register(eachconnection)
poll.poll(5000)
Related