Fixed stucked driver

This commit is contained in:
Kylmakalle 2018-04-14 00:14:07 +03:00
parent e1271bed8d
commit 6f4dfa11d8
2 changed files with 6 additions and 2 deletions

View File

@ -536,6 +536,7 @@ async def stop_command(msg: types.Message):
driver = DRIVERS.get(existing_vkuser.token, '')
if driver:
driver.close()
del DRIVERS[existing_vkuser.token]
existing_vkuser.delete()
await msg.reply('Успешный выход!')
@ -656,6 +657,7 @@ async def handle_text(msg: types.Message):
driver = DRIVERS.get(vkuser.token, '')
if driver:
driver.close()
del DRIVERS[vkuser.token]
TASKS.append({'token': vkuser.token, 'task': asyncio.ensure_future(vk_polling(vkuser))})
await msg.reply(
'Вход выполнен в аккаунт {} {}!\n[Использование](https://asergey.me/tgvkbot/usage/)'.format(

View File

@ -869,7 +869,7 @@ async def vk_polling(vkuser: VkUser):
lp = LongPoll(session, mode=10, version=4)
while VkUser.objects.filter(token=vkuser.token, is_polling=True).exists():
data = await lp.wait()
log.warning('Longpoll: ' + str(data))
log.warning(f'Longpoll id {vkuser.pk}: ' + str(data))
if data['updates']:
for update in data['updates']:
await process_longpoll_event(api, update)
@ -886,8 +886,10 @@ async def vk_polling(vkuser: VkUser):
log.warning('Polling timeout')
asyncio.sleep(5)
except CancelledError:
log.warning('Stopped polling for: id ' + str(vkuser.pk))
log.warning('Stopped polling for id: ' + str(vkuser.pk))
break
except aiohttp.client_exceptions.ServerDisconnectedError:
log.warning('Longpoll server disconnected id: ' + str(vkuser.pk))
except Exception:
log.exception(msg='Error in longpolling', exc_info=True)
asyncio.sleep(5)