-
Notifications
You must be signed in to change notification settings - Fork 46
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
How to get traceback of uncaught exceptions ? #34
Comments
This may very well be a bug, exception_handler should be catching all On Mon, Jun 29, 2015 at 11:26 PM, Insoleet [email protected] wrote:
|
Here you go. """
Created on 1 févr. 2014
@author: inso
"""
import signal
import sys
import asyncio
import logging
from quamash import QEventLoop
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.QtCore import QTimer, pyqtSlot
@asyncio.coroutine
def future_except():
raise Exception("")
def exct_handler(loop, data):
logging.debug("Handled exception {0}".format(data))
class testWidget(QWidget):
def __init__(self):
super().__init__()
logging.debug("Timer except")
QTimer.singleShot(1, self.test_except)
logging.debug("Timer exit")
QTimer.singleShot(1000, self.test_exit)
@pyqtSlot()
def test_except(self):
logging.debug("Async except")
asyncio.async(future_except())
@pyqtSlot()
def test_exit(self):
logging.debug("Exit app")
QApplication.exit(0)
if __name__ == '__main__':
# activate ctrl-c interrupt
signal.signal(signal.SIGINT, signal.SIG_DFL)
logging.basicConfig(format='%(levelname)s:%(module)s:%(message)s',
level=logging.DEBUG)
app = QApplication(sys.argv)
loop = QEventLoop(app)
loop.set_debug(True)
loop.set_exception_handler(exct_handler)
asyncio.set_event_loop(loop)
with loop:
widget = testWidget()
loop.run_forever()
sys.exit() Outputs :
|
I have created a branch for this issue: CI should come back with 1 test failed. |
this is #34 not "37" https://github.com/harvimt/quamash/tree/gh34 |
for some reason the future isn't being deleted, |
I'm trying to take a look into it because I really need this bug to be fixed... |
So from my testings, there are exactly the same count of references using gc.get_referrers when running in debug mode (with pycharm debug mode). With quamash enabled :
With asyncio standard loop :
Without debug mode, here is what I get : With quamash enabled, two referers :
With standard asyncio loop, only one referer :
I'm using the following code to analyse the problem (your test method with pauses and logs to analyse what is happening) : import asyncio
import sys
import gc
import quamash
def task_test():
task1 = None
@asyncio.coroutine
def future_except():
print("coro run")
raise RuntimeError("Test error")
@asyncio.coroutine
def sleep_exit():
nonlocal task1
print("Start sleep")
for i in range(0, 2):
refs = gc.get_referrers(task1)
print("Referers : {0}".format(len(refs)))
for r in refs:
print(r)
yield from asyncio.sleep(1)
print("Removing ref")
task1 = None
for i in range(0, 4):
yield from asyncio.sleep(1)
print("End sleep")
loop.stop()
def exct_handler(loop, data):
print("except handler")
print(data["message"])
print(data["exception"])
#loop = asyncio.new_event_loop()
loop = quamash.QEventLoop(quamash.QApplication(sys.argv))
asyncio.set_event_loop(loop)
loop.set_debug(True)
loop.set_exception_handler(exct_handler)
task1 = asyncio.async(future_except())
asyncio.async(sleep_exit())
loop.run_forever()
task_test() |
Using https://pypi.python.org/pypi/objgraph I was able to get this graph (with a max_depth of 6) : My guess, seeing this graph, is that we can see on the right a QTimer object. As it is not deleted, it prevents the reference on Task._step to be deleted. Thus, the reference on the Task is never deleted. I removed the self._app reference from the QTimer instanciation, and by going deeper I was able to discover a cyclic reference with the task and the QTimer, because of the exception : |
I'll have to remember this tool (obigraph) If I need to debug gc issues in the future. |
Do you plan releasing a new quamash version soon ? :) |
yeah. I've had relatives in town and have been doing stuff. On Mon, Aug 24, 2015 at 8:37 AM, Insoleet [email protected] wrote:
|
Release pushed. On Mon, Aug 24, 2015 at 9:08 AM, Mark Harviston [email protected] wrote:
|
Thanks ! |
Just wondering, why don't you merge gh34 with branch master ? |
I did... I just forgot to On Mon, Sep 14, 2015 at 1:13 PM, Insoleet [email protected] wrote:
|
Ahah :D |
Hi
I'd like to display tracebacks of uncaught exceptions.
At the moment I can't find a way to do it. Setting an exception_handler in the loop never calls it, enabling the debug by every possible way neither does.
Is there any limitations about this I dont know ?
The text was updated successfully, but these errors were encountered: