可以选择()与Windows下的Python文件一起使用吗?
发布时间:2020-12-14 04:10:02 所属栏目:Windows 来源:网络整理
导读:我试图在 Windows下运行以下python服务器: """An echo server that uses select to handle multiple clients at a time.Entering any line of input at the terminal will exit the server."""import selectimport socketimport syshost = ''port = 50000ba
我试图在
Windows下运行以下python服务器:
""" An echo server that uses select to handle multiple clients at a time. Entering any line of input at the terminal will exit the server. """ import select import socket import sys host = '' port = 50000 backlog = 5 size = 1024 server = socket.socket(socket.AF_INET,socket.SOCK_STREAM) server.bind((host,port)) server.listen(backlog) input = [server,sys.stdin] running = 1 while running: inputready,outputready,exceptready = select.select(input,[],[]) for s in inputready: if s == server: # handle the server socket client,address = server.accept() input.append(client) elif s == sys.stdin: # handle standard input junk = sys.stdin.readline() running = 0 else: # handle all other sockets data = s.recv(size) if data: s.send(data) else: s.close() input.remove(s) server.close() 我收到错误消息(10038,’尝试对非套接字的操作’).这可能与python文档中的the remark有关,“Windows上的文件对象是不可接受的,但套接字是.在Windows上,底层的select()函数由WinSock库提供,并且不处理不具有的文件描述符来自WinSock.“在互联网上有很多关于这个主题的帖子,但它们对我来说太技术或者根本不清楚.所以我的问题是:有没有什么方法可以在Windows下使用python中的select()语句?请添加一些示例或修改上面的代码.谢谢!
看起来它不喜欢sys.stdin
如果您将输入更改为此 input = [server] 例外情况将会消失. 这是从the doc Note: File objects on Windows are not acceptable,but sockets are. On Windows,the underlying select() function is provided by the WinSock library,and does not handle file descriptors that don’t originate from WinSock. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- NTFS文件系统误删除数据的恢复教程
- windows-server-2008 – Ping返回IPv6地址
- 如何在WindowStyle =“None”的WPF窗口中执行Min
- 在正在运行的进程上关闭Windows终端
- ntfs – 如何删除名称末尾带有空格的文件和隐藏属
- windows – 如何解决CoUnitialize()上挂起的进程
- .net – 如何使用断点调试Windows服务?
- 对于软件工程师,Microsoft或OpenSource / Linux
- IIS7(Windows)身份验证 – 无法弄清楚为什么新网
- 记 Win10 - Archlinux - Archlinux(Emergency) 三
热点阅读