Forums

Flask app main function is not called

I am trying to write a file with my main function in my app.py file. Eventually, I added this line

    if 'liveconsole' not in gethostname():
        app.run()

after which it worked exactly once. Now, it is back to not working despite no code changes. Here is the exact main I executed when it originally worked. I reload my app every time I make changes.

if __name__ == '__main__':
    clf = update_model(db_path=db,
                   model=clf,
                   batch_size=10000)
    pickle.dump(clf, open(os.path.join(cur_dir,
        'pkl_objects', 'classifier5.pkl'), 'wb')
        , protocol=4)
    if 'liveconsole' not in gethostname():
        app.run()

hi- if you are hosting this as a webapp from our web tab, the main function would not be run. (and you don't need app.run() because we run it for you)

If you want the update model / pickle.dump stuff to run each time you reload, perhaps just put it at the module level (ie. outmost level, outside of main)