Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question