Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Asyncio select.select
#1
What is select.select(rlist, (), (), timeout) doing as far as "waiting" for socket data using asyncio?

My end goal here is to remove the need for select.select as this should speed up my code and offer a little more scalability from what I am reading. I am running this on windows so we don't have the option to use epoll sadly.

Right now I am using loop = asyncio.ProactorEventLoop() for my loop as well for the networking half.

As far as code - I am not sure where to even start here with this to recreate something similar or a way around it.

    return [
        conn for conn in rlist
        if isinstance(conn, SSL.Connection) and conn.pending() > 0
    ] or select.select(rlist, (), (), timeout)[0]
Quote
#2
I'm not an expert in asyncio, however I believe that the add_reader allows you to set up an event that is triggered when data is received, rather than waiting for it to happen. See: 19.5.1.21.3. Watch a file descriptor for read events
Quote
#3
Here is what I have - but this still doesn't make sense really...

def ssl_read_select(rlist, timeout):
    return [
        conn for conn in rlist
        if isinstance(conn, SSL.Connection) and conn.pending() > 0
    ] or await wait_for_socket(rlist)


def reader():
    data = conn.recv(100)
    # We are done: unregister the file descriptor
    loop.remove_reader(rsock)
    # Stop the event loop
    loop.stop()

def wait_for_socket(rlist):
   loop = asyncio.ProactorEventLoop()
   for conn in rlist:
       loop.add_reader(conn, reader)
   loop.run_forever()
   loop.close()
But then again I don't think this would work (even if I did get it to work) because my understanind this loop type doesn't support add_reader base off the documents.

https://docs.python.org/3/library/asynci...loops.html
ProactorEventLoop specific limits:

create_datagram_endpoint() (UDP) is not supported
add_reader() and add_writer() are not supported

Here is what I have - but this still doesn't make sense really... = Just trying to get the idea to work I know the following code will not work of course.

So I can't edit my post? This seems a bit silly to me?
Quote
#4
Quote:So I can't edit my post? This seems a bit silly to me?
There is a 5 post delay. Anti spam measure,
since you jsut made your 5th post you should be good to go
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)