我while loop的相机(带有 opencv)可以在物体移动时拍照。我也想调用一个函数来播放声音。但是当我调用并播放它时,它将在该执行时间内停止循环。我尝试过,ThreadPoolExecutor但不知道如何将它与我的代码混合,因为我没有将任何内容传递给函数。只需从循环中调用它即可。顺便提一句。something如果循环中出现多个代码,我希望能够多次播放它(执行时多次执行)
相机脚本
from play_it import alert
while True:
#do something in cv2
if "something":
alert() # Here it slowing the loop
Run Code Online (Sandbox Code Playgroud)
和我的play_it剧本
from playsound import playsound
import concurrent.futures
def alert():
playsound('ss.mp3')
def PlayIt():
with concurrent.futures.ThreadPoolExecutor() as exe:
exe.map(alert, ???) # not sure what to insert here
Run Code Online (Sandbox Code Playgroud) 我有一个list of dicts这样的:
a = [{'key1':val, 'key2':val, 'key3':val},{'key1':val, 'key2':val, 'key3':val}]
Run Code Online (Sandbox Code Playgroud)
我正在尝试从值到一个列表中获取一个键,如下所示:
a = ['key1', 'key2', 'key3']
Run Code Online (Sandbox Code Playgroud)
有了这个代码
a = ['key1', 'key2', 'key3']
Run Code Online (Sandbox Code Playgroud)
哪个有效,但值的顺序不一样,是不是因为我将数据插入到set?我怎么能用相同的值(键)顺序制作它?