Answer the question
In order to leave comments, you need to log in
Multithreading or a loop in python?
Good day, professionals!
I'm new to Python, I'm writing a simple bot for my needs and I had a dilemma, how to do it right:
a) put almost all the contents of the bot into a loop
b) try to solve the problem through flows
A little about the bot : the bot checks for the current availability of certain nodes that are listed in the settings file. What I would like: the bot in a cycle checks the availability of all nodes available in the settings and issues a one-time problem only if the device status has changed.
Below is the structure of the bot:
Подключение библиотек
Подключение клавиатуры с кнопками /http /ssl /rdp
Функция отправки сообщений всем участникам чата что бот запущен
Функция проверки файлов настроек
Функция проверки списков доступа к чату
# точка №1
Функция проверкп http/https узлов из файла настроек
Функция проверки SSL узлов из файла настроек
Функция проверки RDP узлов из файла настроек
Функция обработки нажатия кнопки /http
вызов функции http/https и вывод в чат статуса доступности узлов
Функция обработки нажатия кнопки /ssl
вызов функции ssl и вывод в чат статуса доступности узлов
Функция обработки нажатия кнопки /rdp
вызов функции rdp и вывод в чат статуса доступности узлов
Функция проверки состояния всех узлов
вызов функции http/https
вызов функции ssl
вызов функции rdp
создание списка недоступных устройств/или изменение статуса и вывод в чат боту
# точка №3
bot.polling()
# точка №2
Answer the question
In order to leave comments, you need to log in
I don't know which is better. In python there are threads, there are processes. Both are manageable: they lock, unlock, queue up. The main difference is that the threads switch in time when the kernel is not involved: pause, output, and I don’t know exactly what else, there is some kind of understandable python switching logic. There are processes that use multi-core and are already running in parallel, not on the same core, like threads. It turns out a thread - emulation of parallel execution, a process - parallel execution under the condition of a multi-core processor.
Some systems may not support multiprocessing. While I'm learning how to use it.
The main code is also a thread, therefore, if you use multithreading, it will also have to be defined as a thread in order to manage it in the future.
https://webdevblog.ru/vvedenie-v-potoki-v-python/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question