我不知道怎么才能msvcrt.kbhit()在python中可以打印出数据,只要我点击指定的键就可以按。看起来while循环需要再循环一次才能打印出我想要的输出。有人能帮帮我吗。我的代码是:
def run(self):
global state
print "\nClient connection received!\n"
self.channel.send("Status: Server connection received")
while 1:
ctr = 1
while 1:
self.clientmess = self.channel.recv(Buffer)
if msvcrt.kbhit():
if msvcrt.getch() == 's':
print "stop"
break
#the codes belo is what i will want for self.clientmess will be so its not necessary I think to put
大多数时候,您的程序阻塞了
recv
调用,因此在接收到某些数据之前,它不会执行kbhit
+getch
。如果需要立即处理键盘输入,则可能需要使套接字非阻塞,并轮询循环中的套接字和键盘,并按显示的方式处理来自它们的数据。在相关问题 更多 >
编程相关推荐