Y
Y
Yevgeni2018-05-28 18:06:27
Python
Yevgeni, 2018-05-28 18:06:27

Why is threading running over and over in a flask app hosted on Heroku?

My __init__.py

from flask import Flask, request
from telebot import TeleBot
from configs import telegram_config

bot = TeleBot(telegram_config.TELEGRAM_API_TOKEN)

app = Flask(__name__)
app.config.update(
    DEBUG=False
)

from bot_functions import news_publisher
from app import views

The file that contains the code with the function that should be executed in parallel:
from app import bot
from time import sleep
from threading import Thread
from random import randint

def sender():
    while True:
        print('turned on')
        random_time = randint(60, 90)
        sleep(random_time)


t = Thread(target=sender, name='sender')
t.start()

so here. The sender function is constantly executed without stopping, and it is also duplicated at startup.
Maybe someone knows how to solve this problem?
Here's my Procfile web: gunicorn app:app and heroku log just in case:
2018-05-28T15:08:52.189169+00:00 app[web.1]: [2018-05-28 15:08:52 +0000] [4] [CRITICAL] WORKER TIMEOUT (pid:8)

2018-05-28T15:08:52.189364+00:00 app[web.1]: [2018-05-28 15:08:52 +0000] [4] [CRITICAL] WORKER TIMEOUT (pid:9)

2018-05-28T15:08:52.190164+00:00 app[web.1]: [2018-05-28 15:08:52 +0000] [8] [INFO] Worker exiting (pid: 8)

2018-05-28T15:08:52.191280+00:00 app[web.1]: [2018-05-28 15:08:52 +0000] [9] [INFO] Worker exiting (pid: 9)

2018-05-28T15:08:53.197374+00:00 app[web.1]: [2018-05-28 15:08:53 +0000] [18] [INFO] Booting worker with pid: 18

2018-05-28T15:08:53.205160+00:00 app[web.1]: [2018-05-28 15:08:53 +0000] [19] [INFO] Booting worker with pid: 19

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2018-05-28
@Yevgeni

Read " 12 factors " to understand how Heroku works and why you can't write programs for this platform the way you wrote.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question