Mayil-AI-Sandbox / loguru-Jan2023

MIT License
0 stars 0 forks source link

` does not work with PySide6 slots (hashtag634) #83

Closed vikramsubramanian closed 2 months ago

vikramsubramanian commented 2 months ago

I am currently developing an application to control some hardware devices. Occasionally, some unexpected behavior will cause errors in my application that I would like to log to fix as they occur.

Unfortunately, it does not appear that works on decorated methods. It also does not appear that changing the order of the decorations makes a difference in terms of my issue or the behavior of PySide6.

When these errors occur, I receive no indication that an error even occurred as PySide suppresses it.

Here is an MRE:

import sys

from loguru import logger
from PySide6.QtCore import QObject, QThread, Slot
from PySide6.QtWidgets import QApplication, QWidget, QPushButton

class Worker(QObject):

    def raise_error(self):
        logger.info("Raising error")
        raise ValueError("Test error")

app = QApplication(sys.argv)
worker = Worker()
worker_thread = QThread()
worker.moveToThread(worker_thread)
worker_thread.start()

window = QWidget()
button = QPushButton("Hello world", window)
button.clicked.connect(worker.raise_error)
window.show()

hashtag Start the event loop.
app.exec_()

As a workaround, using logger.catch as a context manager does work as intended, so I can use that method while we work through this issue.

Thanks, Jules

vikramsubramanian commented 2 months ago

Hi

Your issue seems related to right?

Unfortunately, according to the research I did at that time, it did not seem possible to fix the problem on the Loguru side. It happens due to Qt introspecting the modified signature of the decorated function.

Workaround suggested are either:

vikramsubramanian commented 2 months ago

Apologies, I wrote out a response to you but never hit "Comment" haha. My bad.

Yes, it appears hashtag440 is related. It's unfortunate that Qt does such invasive introspection--I would have thought having ` on top would work, but that appears not to be the case.

Also, PySide6 does not have pyqtSlot, only Slot. sys.excepthook also does not work as I already have one set up--perhaps, because the errors occur in a separate QThread than the main GUI, Qt is silencing them before the caller receives them? That'd be the only thing I can think of.

For now, using with logger.catch is working, so I'll just continue to use that.

Anyways, thanks for the help.