开发者

Creating waitable objects in Python

开发者 https://www.devze.com 2022-12-16 16:07 出处:网络
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 \'us

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 User class implement a fileno(self) method which returns self.thesocket.fileno() -- that's the way to make select work on your own classes (sockets only on windows, arbitrary files on Unix-like systems). Not sure what switch is supposed to me -- don't recognize it as a standard library (or built-in) Python concept...?

0

精彩评论

暂无评论...
验证码 换一张
取 消