Z
Z
ZeroXG2022-04-06 16:28:09
css
ZeroXG, 2022-04-06 16:28:09

[Aiogram] When querying or flooding the database at the same time, it gives an error.?

I use the aiogram library and aiomysql. When I click on the button in the bot several times in a row or simultaneously on two accounts, it gives an error:

spoiler
Task was destroyed but it is pending!
task: wait_for=<_GatheringFuture pending cb=[Task.task_wakeup()]>>
Exception ignored in:
Traceback (most recent call last):
File "C:\Users\Kondor_PC\Desktop\bots\venv\lib\site-packages\aiogram\dispatcher\handler.py", line 126, in notify
current_handler.reset(ctx_token)
ValueError: at 0x00000223B9D95500> was created in a different Context


The code:
from data_base import mysql_db

async def command_info(message: types.Message):
    user = await mysql_db.sql_query(str(message.from_user.id))
    await bot.send_message(message.from_user.id, "Мой ID:" + str(user[0][2]) + "\n\nМонеты: " + str(user[0][4]),
                           parse_mode="Markdown")

mysql_db module:
loop = asyncio.get_event_loop()

async def sql_query(users):
    try:
        conn = await aiomysql.connect(host='None', user='None',
                                      password='None', db='None',
                                      loop=loop)
        cur = await conn.cursor()
        await cur.execute("SELECT * FROM users WHERE username='" + str(users) + "'")
        print("You have successfully query")
        r = await cur.fetchall()
        print(r)
        await cur.close()
        conn.close()
    except Error:
        print("Wrong HOST or LOGIN or PASSWORD.")
        raise (SystemExit)

if __name__ == '__main__':
    loop.run_until_complete(sql_query())

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Bogachev, 2016-08-24
@maxminimus

In this situation, you can do with the usual animation from css (i.e. without setting the width from the script):

@кадры растянуть {
    от { ширина: 0;  }
    до { ширина: 50%; }
}

.страница {
    ширина: 0;
    анимация: растянуть 1s;
}

A
Alan Gibizov, 2022-04-08
@phaggi

read here , it might help.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question