簡體   English   中英

pygame.mixer.music.load(filename) 加載音樂后不釋放文件

[英]pygame.mixer.music.load(filename) does not release the file after the music has been loaded

我想讓 pygame.mixer.music.load(filename) 命令在音樂上傳后釋放文件。 由於它不釋放文件,我無法刪除該文件。 我附上了一個非常簡單的程序來說明這個問題。

import pygame
import os

pygame.mixer.init()

# load the music
pygame.mixer.music.load('music.mp3')

# loop the music
pygame.mixer.music.unpause()
pygame.mixer.music.play(-1)

# delete the music.mp3 file
if os.path.exists('music.mp3'):

    # when we get to this point, the file is still attached to the
    # pygame.mixer.music.load() command and can't be deleted.
    # how can I unlink pygame.mixer.music.load() and the file music.mp3
    # so that the file can be deleted?

    os.remove('music.mp3')
    # ERROR: [WinError 32] The process cannot access the file because it is 
    #                      being used by another process: 'music.mp3'

提前感謝您提供的任何幫助。

pygame.mixer.music.unload()放在os.remove('music.mp3')代碼行之前解決了這個問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM