我已经不知道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
答案 0 :(得分:1)
大多数情况下,您的程序会在recv
调用中阻止,因此在收到某些数据之前,它不会执行kbhit
+ getch
。如果你需要立即处理键盘输入,你可能需要使套接字无阻塞,并在循环中轮询套接字和键盘,处理它们出现的数据。