jim-easterbrook / Photini

An easy to use digital photograph metadata (Exif, IPTC, XMP) editing application.
https://photini.readthedocs.io/
GNU General Public License v3.0
155 stars 24 forks source link

WARNING: CPU random generator seem to be failing, disabling hardware random number generation #134

Open Trung0246 opened 1 year ago

Trung0246 commented 1 year ago

As I'm having a CPU like https://askubuntu.com/questions/1264439/warning-cpu-random-generator-seem-to-be-failing-disable-hardware-random-number and this is a well known issue so far, is there a way to force the hardware RNG using alternative method for random number generation (due to some reason I cannot apply BIOS patch on my machine).

WARNING: CPU random generator seem to be failing, disabling hardware random number generation
WARNING: RDRND generated: 0xffffffff 0xffffffff 0xffffffff 0xffffffff
Traceback (most recent call last):
  File "runpy.py", line 196, in _run_module_as_main
  File "runpy.py", line 86, in _run_code
  File "C:\Program Files (Portable & CMD)\python\lib\site-packages\photini\__main__.py", line 25, in <module>
    sys.exit(main())
  File "C:\Program Files (Portable & CMD)\python\lib\site-packages\photini\editor.py", line 573, in main
    main = MainWindow(options, args)
  File "C:\Program Files (Portable & CMD)\python\lib\site-packages\photini\editor.py", line 180, in __init__
    full_screen = window_state & int(
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'WindowState'
Exception ignored in atexit callback: <function shutdown at 0x000002674364AEF0>
Traceback (most recent call last):
  File "logging\__init__.py", line 2182, in shutdown
  File "logging\__init__.py", line 1084, in flush
  File "C:\Program Files (Portable & CMD)\python\lib\site-packages\photini\loggerwindow.py", line 61, in flush
    self.flush_text.emit()
RuntimeError: Internal C++ object (StreamProxy) already deleted.
jim-easterbrook commented 1 year ago

The only random number usage I can find in Photini is a redundant import of the Python random library package. I don't know any way to tell that package which RNG to use.

You have also discovered another example of the Qt libraries' increasing fussiness about parameter types, so I need to change that.

jim-easterbrook commented 1 year ago

I'm not able to reproduce the TypeError: int() argument must be a string, a bytes-like object or a real number error. Please copy and paste the output of python3 -m photini --version.

Trung0246 commented 1 year ago
WARNING: CPU random generator seem to be failing, disabling hardware random number generation
WARNING: RDRND generated: 0xffffffff 0xffffffff 0xffffffff 0xffffffff
Photini 2022.9.1, build 2260 (5e79c26)
  Python 3.10.7 (tags/v3.10.7:6cc6b13, Sep  5 2022, 14:08:36) [MSC v.1933 64 bit (AMD64)]
  python-exiv2 0.11.3, exiv2 0.27.5
  PySide2 5.15.2.1, Qt 5.15.2, using QtWebEngine
  PyEnchant 3.2.2
  ffmpeg version 5.0-full_build-www.gyan.dev Copyright (c) 2000-2022 the FFmpeg developers
  available styles: windowsvista, Windows, Fusion
  using style: windowsvista
Trung0246 commented 1 year ago

also installing and using PySide2 seems to fix the problem but switching to PySide6 will cause the error I think what I did is not installing PySide2 and only install PySide6

jim-easterbrook commented 1 year ago

Can you change back to PySide6 (use photini-configure) and run python3 -m photini --version again so I can see which versions of PySide6 and Qt6 it uses.

Trung0246 commented 1 year ago

image image

No idea what's wrong with Qt 6

jim-easterbrook commented 1 year ago

OK, I'll have another go at reproducing the problem tomorrow (it's 10pm here in the UK). Meanwhile I suggest you switch back to PySide2 until I release the next version of Photini.

jim-easterbrook commented 1 year ago

I've managed to reproduce the problem. It appears to be introduced in PySide6 v6.4 where Qt enums are no longer converted to Python ints. (My main computer is using an older version of Python and does not have PySide6 later than v6.2.4. I'm using a virtual machine for these tests.) https://doc.qt.io/qtforpython/PySide6/QtCore/QEnum.html

jim-easterbrook commented 1 year ago

I've found several more incompatibilities with PySide6 v6.4. These are fixed in commit a987e97c.

jim-easterbrook commented 1 year ago

If you want to continue using PySide6 then installing v6.3.2 should allow the current release of Photini to work. Use pip install pyside6==6.3.2 to install that version of PySide6. I see that v6.4.0 of PySide6 was released on October 13th, less than a week ago. Thank you for drawing my attention to it.

To solve your RNG problem I think you need to find out which Python package is causing the error. You can test the packages by importing them into Python like this: python -c "import requests_oauthlib"

I suggest trying this with each of these packages: random, requests_oauthlib, keyring, SecretStorage, cryptography, oauthlib. You can find out which packages a package depends on with pip show <package_name>.

jim-easterbrook commented 1 year ago

I've been doing a bit of web searching and another one to try is python -c "from PySide6 import QtCore". Qt has a random number generator that attempts to use hardware. I'm not using it directly, but it's likely that other parts of Qt are using it, which is beyond my control. https://doc.qt.io/qt-6.2/qrandomgenerator.html