Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows 10] When using Python 3.12 psutil.disk_usage is raising an error not seen on other Python versions #2252

Closed
PySimpleGUI opened this issue May 3, 2023 · 9 comments · Fixed by #2270

Comments

@PySimpleGUI
Copy link

Summary

  • OS: Windows 10
  • Architecture: 64-bit
  • Psutil version: 5.9.5
  • Python version: 3.12.0a7
  • Type: core?

Description

This is only happening on Python 3.12A. No other versions of Python are showing this problem (I've tried them all from 3.6-3.11 including PyPy as well). All drives that I try to get usage data from get this error. This is the line of code I'm trying to run:

usage = psutil.disk_usage(mount)

The mount parm I'm passing in has these values that all fail. The string is actually 'A:\\' but prints as:

A:\
B:\
C:\
D:\
E:\
F:\
G:\
H:\
I:\
J:\
X:\
Y:\
Z:\

It doesn't make sense that the code would work on so many other versions of Python. I'm coming up with blanks so thought I would ask here...

image

THANK YOU for a fantastic package. psutil has been a huge part of my projects and provides constant feedback all day about my system. From a detailed look at each core to the overall CPU and RAM used, your work enables it all.

image

image

image

@giampaolo
Copy link
Owner

Hi Mike!

All drives that I try to get usage data from get this error.

What error? I don't see any. Perhaps you forgot to paste it?

@PySimpleGUI
Copy link
Author

I DID forget to paste it! Doh!

image

argument 1 (impossible<bad format char>)

@giampaolo
Copy link
Owner

Don't you have a full python traceback message? I'm not sure where that line is coming from, but it's not psutil.

@PySimpleGUI
Copy link
Author

Lemme remove the try and see if I can get more info for you. Sorry about it being so brief. I'll try again, so to speak....

@PySimpleGUI
Copy link
Author

Let's see if this is better. I hardcoded a call to:

    usage = psutil.disk_usage('A:\\')
  File "C:\Python\PycharmProjects\PSG\MikesDemos\Mike_Desktop_Widget_Drive_Usage.py", line 191, in <module>
    main(location)
  File "C:\Python\PycharmProjects\PSG\MikesDemos\Mike_Desktop_Widget_Drive_Usage.py", line 154, in main
    update_window(window)  # sets the progress bars
    ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python\PycharmProjects\PSG\MikesDemos\Mike_Desktop_Widget_Drive_Usage.py", line 89, in update_window
    usage = psutil.disk_usage('A:\\')
            ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "X:\Python\python3.12\Lib\site-packages\psutil\__init__.py", line 2005, in disk_usage
    return _psplatform.disk_usage(path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "X:\Python\python3.12\Lib\site-packages\psutil\_pswindows.py", line 280, in disk_usage
    total, free = cext.disk_usage(path)
                  ^^^^^^^^^^^^^^^^^^^^^
SystemError: argument 1 (impossible<bad format char>)

Process finished with exit code 1

@PySimpleGUI
Copy link
Author

Here's a 2 line replication I managed to get using REPL:

C:\Python\PycharmProjects\PSG>py312
Python 3.12.0a7 (tags/v3.12.0a7:b861ba4, Apr  4 2023, 16:33:41) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import psutil
>>> psutil.disk_usage('A:\\')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "X:\Python\Python3.12\Lib\site-packages\psutil\__init__.py", line 2005, in disk_usage
    return _psplatform.disk_usage(path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "X:\Python\Python3.12\Lib\site-packages\psutil\_pswindows.py", line 280, in disk_usage
    total, free = cext.disk_usage(path)
                  ^^^^^^^^^^^^^^^^^^^^^
SystemError: argument 1 (impossible<bad format char>)
>>>

@giampaolo
Copy link
Owner

Well, that's weird. Looks like a Python 3.12 bug.

@PySimpleGUI
Copy link
Author

Thank you for the super-fast work on this one! That's the conclusion I came to as well since your stuff is rock solid on all the testing I've been doing, on all versions of Python 3.6-3.11. Only 3.12 has this.

@mayeut
Copy link
Contributor

mayeut commented Jun 25, 2023

This is related to the warning seen in #2255
c.f. https://docs.python.org/3.11/c-api/arg.html

u (str) [const Py_UNICODE *]
Convert a Python Unicode object to a C pointer to a NUL-terminated buffer of Unicode characters. You must pass the address of a Py_UNICODE pointer variable, which will be filled with the pointer to an existing Unicode buffer. Please note that the width of a Py_UNICODE character depends on compilation options (it is either 16 or 32 bits). The Python string must not contain embedded null code points; if it does, a ValueError exception is raised.
Changed in version 3.5: Previously, TypeError was raised when embedded null code points were encountered in the Python string.
Deprecated since version 3.3, will be removed in version 3.12: Part of the old-style Py_UNICODE API; please migrate to using PyUnicode_AsWideCharString().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants