1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

結論

マルチスレッドを使えば、処理を並列に実行できます。
音楽を流す方法は複数見つけたが、今回はpygameを使用しました。

python sample.py

import pygame.mixer
from time import sleep
from concurrent.futures import ThreadPoolExecutor
import bgmSample

def bgm() :
    pygame.mixer.init() #初期化
    pms = pygame.mixer.Sound
    bgm = pms("音楽.wav") #音楽の読み込み
    bgm.play()
    bgm.set_volume(0.1)
    sound_time = bgm.get_length() #音楽の時間分スリープ
    sleep(sound_time )
    bgm.stop(sound_time)
    pygame.mixer.stop()

def shori(): #適当な処理
    for _ in range(15):
        print("a")
        sleep(1)


with ThreadPoolExecutor(max_workers=2, thread_name_prefix="thread") as executor:
    executor.submit(bgm)
    executor.submit(shori)

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?