python - 为什么“if keyboard.is_pressed('q'):”不在我的代码中执行?
问题描述
在我的代码中,在 f() 中,“kbd.is_pressed('q'):”不起作用。当按下“q”时,它不会打印消息并且循环不会结束。
from multiprocessing import Process, Pipe
import multiprocessing as mp
import keyboard as kbd
x = 0
frames = []
def f(conn):
global x
while x == 0:
frames.append(1)
conn.send([42, None, 'hello', frames])
if kbd.is_pressed('q'):
print("Q was pressed.")
break
conn.close()
print("Pipe is closed!")
if __name__ == '__main__':
parent_conn, child_conn = Pipe()
p = Process(target=f, args=(child_conn,))
p.start()
print(mp.current_process)
print(parent_conn.recv()) # prints "[42, None, 'hello']"
f(child_conn)
print(str(frames))
p.join()
print("CPU's = " + str(mp.cpu_count()))
p.terminate()
print(mp.parent_process)
解决方案
推荐阅读
- javascript - 使用 React JS 和 Laravel 将带有图像文件的 POST 请求发送到数据库时出现内部服务器错误
- javascript - 无效的拖放区元素
- c++ - Visual Studio 中的 OpenCV 在运行一次后崩溃
- angular - Okta 身份验证登录
- regex - 如何在 Linux 中读取文件并获取某些行
- django - 在 docker 中为 django 和 postgres 设置 db_password
- reactjs - 使用 react formik 进行空间验证
- java - Springboot 应用程序抛出了 java.lang.IllegalStateException
- css - 在悬停时在 Div 中的 Img 上显示 Box-Shadow
- python - 如何在python中创建和写入文本文件