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:
+10
-2
@@ -78,8 +78,15 @@ def music_separation_task(file_path):
|
|||||||
# Determine the base directory (output path)
|
# Determine the base directory (output path)
|
||||||
output_path = file_path.parent
|
output_path = file_path.parent
|
||||||
|
|
||||||
# Run Demucs separation
|
try:
|
||||||
separate_audio_with_demucs(str(file_path), str(output_path))
|
# 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
|
# Define expected output dir
|
||||||
demucs_dir = output_path / 'htdemucs'
|
demucs_dir = output_path / 'htdemucs'
|
||||||
@@ -116,6 +123,7 @@ def music_separation_task(file_path):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
print(f"Failed to separate music into sources: {e}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@shared_task
|
@shared_task
|
||||||
|
|||||||
Reference in New Issue
Block a user