P
P
plyshk1n2k2020-12-23 21:27:43
PyQt
plyshk1n2k, 2020-12-23 21:27:43

Is there an alternative to QTimer pyqt5?

I connect to a websocket via python websockets and listen to the server in a loop, but I also need to send "websocket.send ('online')" every 60 seconds. so I came up with a function to which I pass the current connection and send "websocket.send('online')" through it. I decided to use QTimer for these purposes (in which the server will be contacted), but when the timer starts, an error appears - "object NoneType can't be used in 'await' expression".

I ask for advice in which direction to google, or suggest an alternative to QTimer.

Code snippet:

async def hello(self):
        try:
            while True:
                print('попытка подключиться к серверу')
                try:
                    get_auth = requests.get(
                        'https://market.csgo.com/api/GetWSAuth/?key=***').text
                    auth_key = json.loads(get_auth)['wsAuth']
                    print('Успешно подключились')
                    break
                except BaseException as err:
                    print('Неудача следующая попытка через 60 сек...')
                    self.msleep(60000)
            uri = "wss://wsn.****"
            async with websockets.connect(uri) as websocket:
                await websocket.send(auth_key)
                # Запускаем QTIMER КОТОРЫЙ БУДЕТ ЗАПУСКАТЬ ФУНКЦИЮ ДЛЯ ОТПРАВКИ PING
                await self.timer_ping.start(60000)
                 #Цикл в котором слушаем сервер
                 while True:
                    print('зашли в цикл')
                    greeting = await websocket.recv()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Jacob E, 2020-12-23
@plyshk1n2k

I don't write in Python, but:
If you're using QTimer, then use Qt's websockets as well . If you use the left implementation, then use the timer not from Qt, for example like this .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question