Flask debug true not taking effect (OS X Yosemite)

286 Views Asked by At

I follow the instructions from:

The run() method is nice to start a local development server, but you would have to restart it manually after each change to your code. That is not very nice and Flask can do better. If you enable debug support the server will reload itself on code changes, and it will also provide you with a helpful debugger if things go wrong.

I set:

app.run(debug=True)

But the debug mode still seems not be activated. What can be the reason?

This is the code (one file only):

import os
import glob

import pandas as pd
from flask import Flask

from regex_file_cleaner import clean_csv_file

app = Flask(__name__)
APP_ROOT = os.path.dirname(os.path.abspath(__file__))
APP_STATIC = os.path.join(APP_ROOT, 'static')


@app.route('/1/1')
def task1():

    array = [['a', 'b', 'c'], ['d', 'e', 'f']]
    result = ' '.join([' '.join(i) for i in array])
    return ("<pre>' '.join([' '.join(i) for i in array])</pre>"
            " applied to:<pre>%s</pre>results in: %s") % (str(array), result)


@app.route('/1/2')
def task2():

    dataframes_collection = []

    os.chdir(APP_STATIC+"/some/path")

    for csv_file in glob.glob("*.csv"):

        country_code = csv_file.split(' ')[1].split('.')[0]
        start, end = clean_csv_file(csv_file)
        df = pd.read_csv(csv_file, sep='\t', header=False, skiprows=start, parse_dates=True)[:end]
        df['Country'] = country_code
        dataframes_collection.append(df)

    concatenated = pd.concat(dataframes_collection, ignore_index=True)

    raport = "<h1>Raw data</h1> %s <h1>Summary of the day.</h1> %s" % (
        concatenated.to_html(),
        concatenated.groupby(
            ['Days'])['Page Impressions', 'Visits', 'Bounces'].sum().to_html(
            justify='right'))

    return raport


@app.route('/')
def hello_world():

    return 'Hello World!'


if __name__ == '__main__':
    app.debug = True
    app.run()

This is the output of my pip freeze:

Flask==0.10.1
Jinja2==2.7.3
MarkupSafe==0.23
Werkzeug==0.9.6
backports.ssl-match-hostname==3.4.0.2
certifi==14.05.14
itsdangerous==0.24
matplotlib==1.3.1
nose==1.3.3
numpy==1.8.1
pandas==0.14.1
pyparsing==2.0.2
python-dateutil==2.2
pytz==2014.4
scipy==0.14.0
six==1.7.3
tornado==4.0
wsgiref==0.1.2

Console output:

(rocket)➜  demo  python test.py
 * Running on http://127.0.0.1:5000/
 * Restarting with reloader
127.0.0.1 - - [02/Aug/2014 19:50:49] "GET /1/2 HTTP/1.1" 404 -
127.0.0.1 - - [02/Aug/2014 19:50:51] "GET /1/2 HTTP/1.1" 404 -
127.0.0.1 - - [02/Aug/2014 19:50:54] "GET /1 HTTP/1.1" 404 -
127.0.0.1 - - [02/Aug/2014 19:50:56] "GET /1/1 HTTP/1.1" 200 -
 * Detected change in 'test.py', reloading
 * Restarting with reloader
127.0.0.1 - - [02/Aug/2014 19:53:37] "GET /1/1 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 19:53:41] "GET /1/2 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 19:53:54] "GET /1/2 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 19:53:57] "GET /1/2 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 19:54:06] "GET /1/2 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 19:54:47] "GET /1/1 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 19:54:54] "GET /1/1 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 19:55:00] "GET /1/1 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 19:58:29] "GET /1/1 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 19:59:15] "GET /1/1 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 19:59:16] "GET /1/1 HTTP/1.1" 200 -
 * Detected change in '/Users/andi/FLASK/demo/regex_file_cleaner.py', reloading
 * Restarting with reloader
 * Detected change in '/Users/andi/FLASK/demo/regex_file_cleaner.py', reloading
 * Restarting with reloader
 * Detected change in 'test.py', reloading
 * Restarting with reloader
 * Detected change in 'test.py', reloading
 * Restarting with reloader
 * Detected change in 'test.py', reloading
 * Restarting with reloader
 * Detected change in 'test.py', reloading
 * Restarting with reloader
 * Detected change in 'test.py', reloading
 * Restarting with reloader
 * Detected change in 'test.py', reloading
 * Restarting with reloader
 * Detected change in 'test.py', reloading
 * Restarting with reloader
 * Detected change in 'test.py', reloading
 * Restarting with reloader
127.0.0.1 - - [02/Aug/2014 20:00:47] "GET /1/2 HTTP/1.1" 200 -



127.0.0.1 - - [02/Aug/2014 20:02:44] "GET /1/2 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 20:04:38] "GET /1/2 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 20:04:42] "GET /1/1 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 20:05:06] "GET /1/1 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 20:05:08] "GET /1/1 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 20:05:14] "GET /1/1 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 20:05:17] "GET /1/1 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 20:05:21] "GET /1/1 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 20:06:10] "GET /1/1 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 20:07:02] "GET /1/1 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 20:07:04] "GET /1/2 HTTP/1.1" 200 -
^C%     

UPDATE:

I noticed that in main file changes are not recognized, but changes made to file regex_file_cleaner.py are recognized always.

0

There are 0 best solutions below