<p dir="ltr">Hello,</p>
<p dir="ltr">I don't see anything wrong with that; in fact, Python is a language where you can do the same thing in many different ways.</p>
<p dir="ltr">I don't really see the advantages of application factories and module globals; if you don't have a Flask instance, you can't use them anyway. If you have a Flask instance, why would you use them instead of class properties?</p>
<p dir="ltr">Right now I'm trying to transition a relatively big Flask app from app factory to Flask subclass. There are a lot of measurements to do, but so far it looks cleaner (to me).</p>
<p dir="ltr">Best,<br>
Gergely</p>
<br><div class="gmail_quote"><div dir="ltr">On Fri, Mar 31, 2017, 14:49 Skip Montanaro <<a href="mailto:skip.montanaro@gmail.com">skip.montanaro@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I'm getting to the point with a smallish Flask application that I<br class="gmail_msg">
really don't want a bunch of module-level global variables sitting<br class="gmail_msg">
around. My initial inclination would be to subclass flask.Flask, but<br class="gmail_msg">
picking through the documentation and the prominent examples<br class="gmail_msg">
(minitwit, etc), I didn't see any examples of this. This leads me to<br class="gmail_msg">
believe that maybe that's not the correct route for corralling my<br class="gmail_msg">
data.<br class="gmail_msg">
<br class="gmail_msg">
I'll give you one small example. My database is actually constructed<br class="gmail_msg">
from a set of files which are updated outside of my control. I'd like<br class="gmail_msg">
to run a separate thread to incrementally update the relevant bits of<br class="gmail_msg">
my database as individual files change. The straightforward (to me)<br class="gmail_msg">
way to do this is to have a separate thread which keeps things<br class="gmail_msg">
up-to-date. As I'm currently using sqlite3, that suggests I need to<br class="gmail_msg">
lock access. Storing the necessary threading.{RLock,Lock} object at<br class="gmail_msg">
the module level seems iffy. I'd prefer to keep it as an instance<br class="gmail_msg">
attribute. Once I've got a subclass, why not put all the<br class="gmail_msg">
implementation in instance methods with the necessary @app.route<br class="gmail_msg">
decorators?<br class="gmail_msg">
<br class="gmail_msg">
So, am I off-base in thinking I should subclass the Flask class? Is<br class="gmail_msg">
there a more prevalent pattern?<br class="gmail_msg">
<br class="gmail_msg">
Thx,<br class="gmail_msg">
<br class="gmail_msg">
Skip Montanaro<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
Flask mailing list<br class="gmail_msg">
<a href="mailto:Flask@python.org" class="gmail_msg" target="_blank">Flask@python.org</a><br class="gmail_msg">
<a href="https://mail.python.org/mailman/listinfo/flask" rel="noreferrer" class="gmail_msg" target="_blank">https://mail.python.org/mailman/listinfo/flask</a><br class="gmail_msg">
</blockquote></div>