我已经想不出python中的msvcrt.kbhit()如何在我单击需要按下的指定键时立即打印出数据。看起来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发布于 2013-03-20 23:03:27
大多数情况下,您的程序会阻塞recv调用,因此在接收到某些数据之前,它不会执行kbhit+getch。如果您需要立即处理键盘输入,则可能需要使套接字成为非阻塞的,并在循环中轮询套接字和键盘,处理来自它们的数据。
https://stackoverflow.com/questions/15526484
复制相似问题