tartley / colorama

Simple cross-platform colored terminal text in Python
BSD 3-Clause "New" or "Revised" License
3.58k stars 255 forks source link

Permission Error: [WinError 31] A device attached to the system is not functioning #368

Open JeLuF opened 1 year ago

JeLuF commented 1 year ago

We have a few users that are encountering the above error:

  File "D:\INSTALL\stable-diffusion-ui\stable-diffusion\env\Lib\site-packages\torch\hub.py", line 485, in download_url_to_file
    pbar.update(len(buffer))
  File "D:\INSTALL\stable-diffusion-ui\stable-diffusion\env\Lib\site-packages\tqdm\std.py", line 1256, in update
    self.refresh(lock_args=self.lock_args)
  File "D:\INSTALL\stable-diffusion-ui\stable-diffusion\env\Lib\site-packages\tqdm\std.py", line 1361, in refresh
    self.display()
  File "D:\INSTALL\stable-diffusion-ui\stable-diffusion\env\Lib\site-packages\tqdm\std.py", line 1509, in display
    self.sp(self.__str__() if msg is None else msg)
  File "D:\INSTALL\stable-diffusion-ui\stable-diffusion\env\Lib\site-packages\tqdm\std.py", line 350, in print_status
    fp_write('\r' + s + (' ' * max(last_len[0] - len_s, 0)))
  File "D:\INSTALL\stable-diffusion-ui\stable-diffusion\env\Lib\site-packages\tqdm\std.py", line 343, in fp_write
    fp.write(_unicode(s))
  File "D:\INSTALL\stable-diffusion-ui\stable-diffusion\env\Lib\site-packages\tqdm\utils.py", line 145, in inner
    return func(*args, **kwargs)
  File "D:\INSTALL\stable-diffusion-ui\stable-diffusion\env\Lib\site-packages\colorama\ansitowin32.py", line 47, in write
    self.__convertor.write(text)
  File "D:\INSTALL\stable-diffusion-ui\stable-diffusion\env\Lib\site-packages\colorama\ansitowin32.py", line 177, in write
    self.write_and_convert(text)
  File "D:\INSTALL\stable-diffusion-ui\stable-diffusion\env\Lib\site-packages\colorama\ansitowin32.py", line 205, in write_and_convert
    self.write_plain_text(text, cursor, len(text))
  File "D:\INSTALL\stable-diffusion-ui\stable-diffusion\env\Lib\site-packages\colorama\ansitowin32.py", line 210, in write_plain_text
    self.wrapped.write(text[start:end])
PermissionError: [WinError 31] A device attached to the system is not functioning

Python is started from a cmd window. The colorama version is 0.4.6 on Windows 10. The script is run as normal user.

Do you have any idea why this might happen?

ChicknTendr commented 1 year ago

There are a few possible reasons why you might be encountering this PermissionError when trying to write to a file using the tqdm library:

  1. The file you are trying to write to might be located in a protected system directory, in which case you may need to run the script as an administrator to have sufficient permissions.

  2. The file you are trying to write to might be in use by another program or process. If another program has the file open and locked, you will not be able to write to it until it is released.

  3. If you are trying to write to a file on a network drive, make sure that the network connection is stable and that you have the necessary permissions to access the file.

  4. There might be an issue with the colorama library, which is used by tqdm to display progress bars in the terminal. You could try upgrading to the latest version of colorama to see if this resolves the issue.

JeLuF commented 1 year ago

My understanding is that colorama is a library to enable color support in the Windows cmd terminal emulator. tqdm is a library to draw a progress bar. The 'file' that tqdm is writing the progress bar to is stdout, which writes to the terminal, so I think we can rule out options 1 to 3 as they only apply to files in a filesystem.

As stated above, the colorama version in use is 0.4.6, which seems to be the latest version available.

Some research on the Internet revealed a few reports where users encountered this error when using Unicode codepages like 65001. The user who reported this bug to us is using codepage 437.