spotDL / spotify-downloader

Download your Spotify playlists and songs along with album art and metadata (from YouTube if a match is found).
https://spotdl.readthedocs.io/en/latest/
MIT License
16.91k stars 1.56k forks source link

PermissionError: The process cannot access the file because it is being used by another process #1448

Closed finn021 closed 2 years ago

finn021 commented 2 years ago

When downloading an album or playlist, this error is thrown out at random. It has appeared on many different albums and at different times.

System OS

Windows

Python Version

3.10

Install Source

pip / PyPi

Install version / commit hash

v3.9.1

Expected Behavior vs Actual Behavior

Expected: Song is downloaded

Actual: Error is thrown

Steps to reproduce

  1. Download any song/album/playlist.

Traceback

Traceback (most recent call last):
  File "C:\Users\finnb_wn3i83p\AppData\Roaming\Python\Python310\site-packages\spotdl\download\downloader.py", line 258, in download_song
    downloaded_file_path.unlink()
  File "C:\Program Files\Python310\lib\pathlib.py", line 1204, in unlink
    self._accessor.unlink(self)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'spotdl-temp\\thqVSPJL38Y.webm'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\finnb_wn3i83p\AppData\Roaming\Python\Python310\site-packages\spotdl\console\__init__.py", line 75, in console_entry_point
    downloader.resume_download_from_tracking_file(tracking_file)
  File "C:\Users\finnb_wn3i83p\AppData\Roaming\Python\Python310\site-packages\spotdl\download\downloader.py", line 110, in resume_download_from_tracking_file
    self._download_asynchronously(song_list)
  File "C:\Users\finnb_wn3i83p\AppData\Roaming\Python\Python310\site-packages\spotdl\download\downloader.py", line 115, in _download_asynchronously
    self.loop.run_until_complete(asyncio.gather(*tasks))
  File "C:\Program Files\Python310\lib\asyncio\base_events.py", line 641, in run_until_complete
    return future.result()
  File "C:\Users\finnb_wn3i83p\AppData\Roaming\Python\Python310\site-packages\spotdl\download\downloader.py", line 124, in _pool_download
    return await self.download_song(song_obj)
  File "C:\Users\finnb_wn3i83p\AppData\Roaming\Python\Python310\site-packages\spotdl\download\downloader.py", line 263, in download_song
    display_progress_tracker.notify_error(e, tb)
  File "C:\Users\finnb_wn3i83p\AppData\Roaming\Python\Python310\site-packages\spotdl\download\progress_ui_handler.py", line 269, in notify_error
    self.update(message="Error " + self.status)
  File "C:\Users\finnb_wn3i83p\AppData\Roaming\Python\Python310\site-packages\spotdl\download\progress_ui_handler.py", line 289, in update
    self.parent._rich_progress_bar.start_task(self.task_id)
  File "C:\Users\finnb_wn3i83p\AppData\Roaming\Python\Python310\site-packages\rich\progress.py", line 722, in start_task    task = self._tasks[task_id]
KeyError: 249

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\finnb_wn3i83p\AppData\Roaming\Python\Python310\Scripts\spotdl.exe\__main__.py", line 7, in <module>
  File "C:\Users\finnb_wn3i83p\AppData\Roaming\Python\Python310\site-packages\spotdl\console\__init__.py", line 57, in console_entry_point
    with DownloadManager(args_dict) as downloader:
  File "C:\Users\finnb_wn3i83p\AppData\Roaming\Python\Python310\site-packages\spotdl\download\downloader.py", line 60, in __exit__
    shutil.rmtree(temp_folder)
  File "C:\Program Files\Python310\lib\shutil.py", line 739, in rmtree
    return _rmtree_unsafe(path, onerror)
  File "C:\Program Files\Python310\lib\shutil.py", line 617, in _rmtree_unsafe
    onerror(os.unlink, fullname, sys.exc_info())
  File "C:\Program Files\Python310\lib\shutil.py", line 615, in _rmtree_unsafe
    os.unlink(fullname)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'spotdl-temp\\9G8XjPyQk8c.webm'

Other details

Python version: 3.10

xnetcat commented 2 years ago

Well the exception is pretty self descriptive. Maybe some other application is accessing the file, or you 2 instances of spotdl are running at the same time.

I personally saw it few times, but it's really hard to reproduce it (it's random at least in my case) so I can't really debug it.