Answer the question
In order to leave comments, you need to log in
How to stop the current thread?
global t_annul
def worker(id_order, date_order):
t_annul = threading.currentThread()
while getattr(t_annul, 'do_run', True): # запускаю счетчик
print (f"working on {id_order}, {date_order}")
time.sleep(20) # если время не прошло, жду
conn_DB.upd_statusOrders('Аннулирован', id_order)
bot.send_message(message.chat.id, text = f'*\u3030ЗАКАЗ №{id_order} АННУЛИРОВАН* от {date_order} на сумму {zakaz[3]} руб.',
parse_mode = "Markdown", reply_markup = send_keyb_order(buttons.ls_keybs_orders(message.chat.id)[2]))
t_annul.do_run = False # остановка потока
if zakaz[0] == 'Оплата онлайн':
t_annul = threading.Thread(target=worker, args=(f"{conn_DB.id_Zakaz()}", f"{zakaz[2]}"))
t_annul.start()
if 'ОтменаЗаказа' in text:
t_annul.do_run = False
Answer the question
In order to leave comments, you need to log in
import multiprocessing
import time
def send_annul(sec, id_order, date_order, sum_order):
print('Заказ №' + id_order)
time.sleep(sec) # через 15 сек отправляю сообщение # если время не прошло, жду
conn_DB.upd_statusOrders('Аннулирован', int(id_order))
def worker():
global proc
# proc = multiprocessing.Process(target=worker(f"{conn_DB.id_Zakaz()}", f"{zakaz[2]}", f"{zakaz[4]}"))
proc = multiprocessing.Process(target=send_annul, args=(10, f"{conn_DB.id_Zakaz()}", 1, 1))
print(proc)
proc.start()
# proc.terminate()
worker()
if 'ОтменаЗаказа' in text:
print('остановка потока')
print(proc)
proc.terminate()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question