Python 挂起与显示器的连接
考虑以下代码:Python 挂起与显示器的连接,python,Python,考虑以下代码: #!/usr/bin/env python from Xlib.display import Display import os def main(): disp = Display() # connect to display while True: print("1") event = disp.next_event() print("2")
#!/usr/bin/env python
from Xlib.display import Display
import os
def main():
disp = Display() # connect to display
while True:
print("1")
event = disp.next_event()
print("2")
if event.type == Xlib.protocol.event.KeyPress:
print("keypress!")
if __name__ == '__main__':
main()
此代码输出1
,但不输出2
。它似乎挂在显示器连接上。为什么会这样?谢谢。方法next\u event()是一种阻塞方法,请参阅:
返回事件队列中的下一个事件。如果事件队列为空,
阻止,直到从网络读取事件,然后返回该事件
如果它被阻止,那是因为没有事件到达