M
M
Mikhail Muntyan2022-02-15 00:31:18
Python
Mikhail Muntyan, 2022-02-15 00:31:18

How to implement a data change system in a database?

I am writing a game bot in python + aiogram + sqlite. I want to know how to better implement one system, I can’t explain, I’ll give an example:
Messages from the user are processed in one script, there is a mining farm for the user, which once an hour should add cryptocurrency to the user and update it all in the database.
Writing this system somewhere in one script just like that is not an option, the bot will pause, you can resort to multithreading, or to study asynchrony, or maybe there is a better option, please tell me.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2022-02-15
@limontasher

Well, firstly, if you use aiogram, then it is better to forget about multithreading. Asynchrony with multithreading is combined quite badly. It's possible, but not trivial, and newbies are best off not messing around.
Secondly, let me guess - you implement the delay in the farming cycle through time.sleep()? If yes, then of course, the asynchronous program loop stops for that time. That's why the asyncio.sleep() function is provided, which can pause the execution of a single coroutine without affecting the others.
Thirdly, if you need to execute a coroutine and wait for the result of its execution, use the await operator. If you need to schedule the execution of a coroutine and move on without waiting for its result (execution "as soon as immediately"), it is better to use asyncio.get_event_loop().create_task().
I think you can figure out the rest yourself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question