Python Forum
Asyncio select.select - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Networking (https://python-forum.io/forum-12.html)
+--- Thread: Asyncio select.select (/thread-12156.html)



Asyncio select.select - Mradr - Aug-12-2018

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]



RE: Asyncio select.select - Larz60+ - Aug-12-2018

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


RE: Asyncio select.select - Mradr - Aug-12-2018

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/asyncio-eventloops.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?


RE: Asyncio select.select - Larz60+ - Aug-12-2018

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