Python app on heroku platform seems to start on two threads

Viewed 878

There is a simple python app which is deployed on heroku platform:

from flask import Flask

log("APP STARTED.")
# single time connection to database and logging stuff

app = Flask(__name__)

@app.route('/', methods=['GET'])
# do something

@app.route('/', methods=['POST'])
# do something

Procfile:

web: gunicorn app:app --log-file=-

When looking into logs i see that my code above was executed multiple times with multiple threads. I know that there must be more threads involved because of the inconsistent logging. See log:

2017-05-31T17:12:46.415059+00:00 app[web.1]: APP STARTED.   
2017-05-31T17:12:46.415072+00:00 app[web.1]: Executing query.  
2017-05-31T17:12:46.415688+00:00 app[web.1]: APP STARTED.    
2017-05-31T17:12:46.415717+00:00 app[web.1]: Executing query.
2017-05-31T17:12:46.436370+00:00 app[web.1]: Successful connection to database.    
2017-05-31T17:12:46.437398+00:00 app[web.1]: Successful connection to database.    
2017-05-31T17:12:46.439197+00:00 app[web.1]: Success executing query.    
2017-05-31T17:12:46.439680+00:00 app[web.1]: Success executing query.

Also i can see worker threads here:

2017-05-31T18:59:10.046388+00:00 app[web.1]: [2017-05-31 18:59:10 +0000] [9] [INFO] Booting worker with pid: 9    
2017-05-31T18:59:10.132547+00:00 app[web.1]: [2017-05-31 18:59:10 +0000] [11] [INFO] Booting worker with pid: 11

How do i prevent multiple worker-threads booting up and start only with one?

1 Answers
Related