I more or less know how to use select() to take a list of sockets, and only return the ones that are ready to read/write something. The project I’m working on now has a class called ‘user’. Each ‘user’ object contains its own socket. What I would like to do is pass a list of users to a select(), and get back a list of only the users where user.socket is ready to read/write. Any thoughts on where to start on this?
Edit: Changed switch() to select(). I need to proofread better.
You should have your
Userclass implement afileno(self)method which returnsself.thesocket.fileno()— that’s the way to makeselectwork on your own classes (sockets only on windows, arbitrary files on Unix-like systems). Not sure whatswitchis supposed to me — don’t recognize it as a standard library (or built-in) Python concept…?