在python中调用select

编程入门 行业动态 更新时间:2024-10-12 05:52:15
本文介绍了在python中调用select的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试编写套接字服务器.服务器本身并没有完成所有有趣的事情.现在,我的问题是python抱怨我的选择参数.这是一段代码.

I am trying to write a socket server. The server itself doesn't accomplish anything all that interesting. Right now my problem is that python is complaining about my arguments to select. Here is a snippet of code.

read_client_sockets=[the_socket, clients] write_client_sockets=[clients, signals] error=[] #This is the loop that does most everything. while 1: #try to find someone who is ready for input ready_to_read, ready_to_write, in_error = select.select(all_client_sockets, write_client_sockets, error)

这是我从编译器收到的投诉.我试图调整参数并最终得到相同的结果.我也希望它以阻止模式运行.据我所知,可以不指定超时参数;根据文档,我认为它是可选的.感谢您的时间.对于没有其他有趣的事情,我深表歉意.

Here is the complaint that I receive from my compiler. I have tried tweaking the arguments and end up getting the same result. Also I want this to run in blocking mode. As far as i know it is okay to not specify a timeout parameter; according to documentation I believe it is optional. Thank you for your time. I apologize for not having something more interesting to consider.

File "server.py", line 58, in main ready_to_read, ready_to_write, in_error = select.select(all_client_sockets, write_client_sockets, error) TypeError: argument must be an int, or have a fileno() method.

推荐答案

您需要传入三个文件描述符序列 作为参数,从您提供的名称中选择[clients, signals]可能是其他构造(客户端是文件描述符列表吗?).在这种情况下,您可以将clients+signals用作select的第二个参数.

You need to pass in three sequences of file descriptors as arguments to select, from the names you supply I think that [clients, signals] might be some other construct (is clients a list of file descriptors?). In this case you could use clients+signals as second argument to select.

换句话说:每个参数必须是 flat 序列,不允许嵌套.

In other words: Each argument must be a flat sequence, no nesting is allowed.

更多推荐

在python中调用select

本文发布于:2023-08-01 21:43:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1271999.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:python   select

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!