handle FileNotFound Exception in separate task

remove dir_path when websocket disconnects during separation, and dir_path ends up being created again
This commit is contained in:
Joel Mathew Thomas
2025-03-20 00:35:59 +05:30
parent 6a91261e2d
commit 00f16d5814
+10 -2
View File
@@ -78,8 +78,15 @@ def music_separation_task(file_path):
# Determine the base directory (output path)
output_path = file_path.parent
# Run Demucs separation
separate_audio_with_demucs(str(file_path), str(output_path))
try:
# Run Demucs separation
separate_audio_with_demucs(str(file_path), str(output_path))
except Exception as e:
print(f"Failed to separate music into sources: {e}")
if os.path.exists(os.path.dirname(file_path)):
shutil.rmtree(os.path.dirname(file_path))
return False
# Define expected output dir
demucs_dir = output_path / 'htdemucs'
@@ -116,6 +123,7 @@ def music_separation_task(file_path):
return True
except Exception as e:
print(f"Failed to separate music into sources: {e}")
return False
@shared_task