python - How do I remove globals from Flask API calls? -


i working on flask application run foo. once foo running, should possible hit endpoints @ hostname:8080 perform api call changes state of foo.

below minimal (though not complete) example. methods , functions referenced aren't terribly important question global object state being affected.

__foo = none app = flask(__name__)  @app.route("/start_foo") def start_foo():     return __foo._do_foo_init() or ""  def run_foo(foo, debug=false):     """     entry point clients run foo     :param foo:     :return:     """     global __foo     __foo = foo     t = threading.thread(target=delayed_registration, args=(foo,))     t.start()     app.run(host=hostname, debug=debug, port=8080) 

when user calls run_foo, provide bar, subclass of foo, shouldn't matter.

i thinking making @app.route method of class , have foo member of class, don't know if possible within flask.

does have recommendations how remove global __foo in above application?

in flask should store application global objects in flask.g (see documentation more information). true "local" application, in flask should possible have multiple application in same python interpreter. flask documentation states:

since 1 of pillars of flask’s design can have more 1 application in same python process.

so besides configuration should not global local flask application.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -