Issue
Since Python 3.10 I've a trouble with argument 1 has unexpected type 'float' error when using asynqt asyncio.sleep functions whereas it was working well with Python 3.9
the code to reproduce is below and fails on the line await asyncio.sleep(0.1). This works well with interger values. Was working with previous version of Python :
import functools
import sys, traceback
import asyncio, asyncqt
from PyQt5 import QtWidgets, uic
from PyQt5.QtWidgets import QMainWindow
# unknown exception handler
def handle_excepthook(type, message, stack):
print(f'An unhandled exception occured: {message}. Traceback: {traceback.format_tb(stack)}')
class MainUi(QMainWindow):
def __init__(self):
pass
async def main():
app = QtWidgets.QApplication(sys.argv)
app.setQuitOnLastWindowClosed(True)
loop = asyncqt.QEventLoop(app)
asyncio.set_event_loop(loop)
await asyncio.sleep(0.1) # fails with float values
ui = MainUi()
ui.show()
with loop:
# Run the event loop until the UI is closed
await asyncio.gather(loop.create_task(loop.run_forever()), loop.run_in_executor(None, functools.partial(ui.show)))
# Cleanup and close the application
loop.close()
app.exec_()
if __name__ == '__main__':
try:
asyncio.run(main())
except Exception as e:
print("An error occurred:", e)
traceback.print_exc()
sys.exit(1)
this produces the error :
File "C:\PLDesign\AntennaNoiseTracking\venv\Lib\site-packages\asyncqt\__init__.py", line 202, in add_callback
timerid = self.startTimer(delay * 1000)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: startTimer(self, interval: int, timerType: Qt.TimerType = Qt.CoarseTimer): argument 1 has unexpected type 'float'
Any idea ? Thanks Stéphane
Solution
While trying to contact the owner of asynqt I've figured out that it's not maintained anymore since three years.
You can use QAsync instead which is maintained and then replace asynqt by qasync while creating the event loop :
def main():
app = QtWidgets.QApplication(sys.argv)
loop = qasync.QEventLoop(app)
asyncio.set_event_loop(loop)
The on-the-fly casting from float to int is apparently corrected in qasync and the stuff runs perfectly now.
Answered By - Stéphane REY
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.