一 问题描述
OSError: [Errno 117] Structure needs cleaning: '/tmp/pymp-wafeatri'
我重新使用SSH登录也会提示这个类似问题
二 解决方法
2.1 尝试删除报错的文件 (想直接看最终解决方法的可忽略此处)
sudo rm -rf /tmp/pymp-wafeatri
此种方法只能保证当前epoch不报错,下一个epoch依然会报错。(不好用)
2.2 定位原始代码
定位到使用系列临时文件夹的代码66行、67行;
#修改前源代码
def repitch(wav, pitch, tempo, voice=False, quick=False, samplerate=44100):"""tempo is a relative delta in percentage, so tempo=10 means tempo at 110%!pitch is in semi tones.Requires `soundstretch` to be installed, seehttps://www.surina.net/soundtouch/soundstretch.html"""infile = tempfile.NamedTemporaryFile(suffix=".wav")outfile = tempfile.NamedTemporaryFile(suffix=".wav")save_audio(wav, infile.name, samplerate, clip='clamp')command = ["soundstretch",infile.name,outfile.name,f"-pitch={pitch}",f"-tempo={tempo:.6f}",]if quick:command += ["-quick"]if voice:command += ["-speech"]try:sp.run(command, capture_output=True, check=True)except sp.CalledProcessError as error:raise RuntimeError(f"Could not change bpm because {error.stderr.decode('utf-8')}")wav, sr = ta.load(outfile.name)assert sr == sampleratereturn wav
解决方法:修改代码,设置delete=False,添加try-except-finally,在finally中手动关闭文件,删除文件。保证即使报错也能正常关闭文件,删除文件。
#修改后代码
def repitch(wav, pitch, tempo, voice=False, quick=False, samplerate=44100):"""tempo is a relative delta in percentage, so tempo=10 means tempo at 110%!pitch is in semi tones.Requires `soundstretch` to be installed, seehttps://www.surina.net/soundtouch/soundstretch.html"""infile = tempfile.NamedTemporaryFile(suffix=".wav", delete=False)outfile = tempfile.NamedTemporaryFile(suffix=".wav", delete=False)try:save_audio(wav, infile.name, samplerate, clip='clamp')command = ["soundstretch",infile.name,outfile.name,f"-pitch={pitch}",f"-tempo={tempo:.6f}",]if quick:command += ["-quick"]if voice:command += ["-speech"]try:sp.run(command, capture_output=True, check=True)except sp.CalledProcessError as error:raise RuntimeError(f"Could not change bpm because {error.stderr.decode('utf-8')}")wav, sr = ta.load(outfile.name)assert sr == samplerateexcept Exception as e:print('error', e)finally:infile.close()outfile.close()os.remove(infile.name)os.remove(outfile.name)return wav