我想連續播放嘟嘟聲,直到文本在終端上動態顯示。這裏是我的代碼。如何在python中動態顯示文本時在後臺播放聲音?
import time
import sys
import winsound
winsound.Beep(1000, 5000)
def printf(s):
for c in s:
sys.stdout.write('%s' % c)
sys.stdout.flush()
time.sleep(0.0203)
printf("Hello I am Jishan Bhattacharya.")
那聞起來像多線程,多處理RESP如果先不工作,你可以執行嘟嘟聲與寫作文本另一個線程,所以他們在西港島線相同常,[多線程(HTTPS執行://www.tutorialspoint。 com/python/python_multithreading.htm)[multiprocessing](https://pymotw.com/2/multiprocessing/basics.html)。多線程更簡單,但有可能因爲python GIL(python無法使用線程,只有快速切換執行路徑)而無法工作。 – tino415