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

Add slow_callback_duration logging #114

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kormax
Copy link

@kormax kormax commented Mar 17, 2024

This PR resolves an issue encountered in #100 by adding functionality for logging slow handle._run invocations the same way it's done by asyncio.BaseEventLoop(events.AbstractEventLoop).

It the modifies _SimpleTimer.timerEvent function by adding handle invocation time tracking in case debug mode is enabled, tightly mimicking the code from asyncio.base_events.

Results of this change can be compared by running the following code:

1.1. asyncio plain code

# Test asyncio example

import asyncio
import time


async def main():
    time.sleep(1)  # Block event loop


if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    loop.set_debug(True)  # Enable debug
    loop.slow_callback_duration = 0.1
    loop.run_until_complete(main())

1.2. asyncio plain result

Executing <Task finished name='Task-1' coro=<main() done, defined at /Users/username/Documents/qasync_demo.py/blocking_timer_asyncio.py:5> result=None created at /lib/python3.8/asyncio/base_events.py:595> took 1.005 seconds

2.1. qasync code

# Qasync loop example


import time

from qtpy.QtGui import QGuiApplication
from qasync import QEventLoop


async def main():
    time.sleep(1)  # Block event loop

if __name__ == "__main__":
    app = QGuiApplication([])
    loop = QEventLoop(app)
    loop.set_debug(True)  # Enable debug
    loop.slow_callback_duration = 0.1
    loop.run_until_complete(main())

2.2. qasync result

Executing <Task finished name='Task-1' coro=<main() done, defined at /Users/username/Documents/qasync_demo.py/blocking_timer_qasync.py:7> result=None created at /Users/username/Documents/qasync/qasync/__init__.py:415> took 1.001 seconds

P.S. The _current_handle is set during debug handle invocations in order to improve logging in case asyncio.BaseEventLoop.default_exception_handler is set as an exception handler and an exception occurs. It's not mandatory for this change, but is nice to have, considering it's set in the same part of the code.

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

Successfully merging this pull request may close these issues.

1 participant