在python中调用select [英] Calling select in python

查看:89
本文介绍了在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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆