axeldelafosse / stemgen

🎛 Stemgen is a Stem file generator. Convert any track into a Stem and have fun with Traktor.
https://stemgen.dev
MIT License
212 stars 39 forks source link

[Bug] Windows cleaning step failing #37

Closed Cartasiane closed 1 year ago

Cartasiane commented 1 year ago

I always get this error on different windows install:

[Done 6/6]

creating E:\Users\Rouniald\Music\stemgen-master\.\output/Olmatri - Kaspar/Olmatri - Kaspar.stem.m4a was successful!
Done.
Cleaning...
Traceback (most recent call last):
  File "E:\Users\Rouniald\Music\stemgen-master\stemgen.py", line 427, in <module>
    main()
  File "E:\Users\Rouniald\Music\stemgen-master\stemgen.py", line 422, in main
    run()
  File "E:\Users\Rouniald\Music\stemgen-master\stemgen.py", line 302, in run
    clean_dir()
  File "E:\Users\Rouniald\Music\stemgen-master\stemgen.py", line 415, in clean_dir
    shutil.rmtree(os.path.join(OUTPUT_PATH + "/" + FILE_NAME))
  File "C:\Users\rouniald\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 759, in rmtree
    return _rmtree_unsafe(path, onerror)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\rouniald\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 626, in _rmtree_unsafe
    onerror(os.rmdir, path, sys.exc_info())
  File "C:\Users\rouniald\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 624, in _rmtree_unsafe
    os.rmdir(path)
PermissionError: [WinError 32] Le processus ne peut pas accéder au fichier car ce fichier est utilisé par un autre processus: 'E:\\Users\\Rouniald\\Music\\stemgen-master\\.\\output/Olmatri - Kaspar'
axeldelafosse commented 1 year ago

Thank you for the report! It is a known (and annoying) issue.

I'm not familiar enough with Windows to understand and fix this quickly, I need to dig. PRs are welcomed! This is a good first issue, if you ever want to try to fix it :)

Ma5onic commented 1 year ago

The error message: (PermissionError: [WinError 32] The process cannot access the file because it is being used by another process) indicates that some process is still using a file or directory in the folder you're trying to remove with shutil.rmtree().

This is because stemgen is using os.chdir(os.path.join(OUTPUT_PATH, FILE_NAME)) to change the current working directory. If the Python process (or any other running process) is in the directory you're trying to delete, you'll get a permission error. Before removing the directory, you should change back to some other directory.

I made a pull request (https://github.com/axeldelafosse/stemgen/pull/39) with the following changes to the cleanup process: Bug Fix:

I also added the following improvement for windows users with a GPU:

awesomer commented 1 year ago

FWIW, Demucs without any -d flag defaults to CUDA-if-available-otherwise-CPU.

Ma5onic commented 1 year ago

@awesomer, yes but there isn't a way of doing that without changing the code because "cpu" is set as the default value in argparse. So if I omit the -d flag, stemgen defaults back to -d cpu

axeldelafosse commented 1 year ago

Fixed by https://github.com/axeldelafosse/stemgen/pull/39. Closing this!