我在 python 中的选择有问题,我有一段代码允许客户端从服务器接收数据并通过在标准输入上读取并在服务器套接字上写入来发送它:
readfds = [s, sys.stdin]
writefds = [s, sys.stdout]
my_level = get_my_level(s)
is_co = True
cmd = ""
while (is_co):
read, write, exception = select.select(readfds, writefds, [], 1)
if (not (read or write or exception)):
print "Timeout"
else:
for sock in read:
if (sock == s):
cmd = readline(s)
print cmd
elif (sock == sys.stdin):
cmd = sys.stdin.readline()
s.sendall(cmd)
if (cmd == "mort"):
is_co = False
我认为这是因为选择是非阻塞的,但是当我让它阻塞时,它是同一回事。您能解释一下我的代码中的 wath 错误吗?
谢谢