Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lazily importing flask #95

Merged
merged 3 commits into from
Dec 6, 2019
Merged

lazily importing flask #95

merged 3 commits into from
Dec 6, 2019

Conversation

kzidane
Copy link
Member

@kzidane kzidane commented Oct 31, 2019

When flask is imported before cs50:

$ cat application.py
from flask import Flask, jsonify
from cs50 import SQL

app = Flask(__name__)
db = SQL('sqlite:///test.db')

@app.route('/')
def index():
    return jsonify(db.execute('select 1'))
$ flask run
 * Serving Flask app "application.py" (lazy loading)
 * Environment: development
 * Debug mode: off
 * Running on http://localhost:8080/ (Press CTRL+C to quit)
 * Restarting with stat
DEBUG:cs50:select 1
INFO:werkzeug:172.17.0.1 - - [31/Oct/2019 14:30:08] "GET / HTTP/1.1" 200 -
$ curl http://localhost:8080
[{"1":1}]

When flask is imported after cs50:

$ cat application.py
from cs50 import SQL
from flask import Flask, jsonify

app = Flask(__name__)
db = SQL('sqlite:///test.db')

@app.route('/')
def index():
    return jsonify(db.execute('select 1'))
$ flask run
 * Serving Flask app "application.py" (lazy loading)
 * Environment: development
 * Debug mode: off
 * Running on http://localhost:8080/ (Press CTRL+C to quit)
 * Restarting with stat
DEBUG:cs50:select 1
INFO:werkzeug:172.17.0.1 - - [31/Oct/2019 14:32:19] "GET / HTTP/1.1" 200 -
$ curl http://localhost:8080
[{"1":1}]

Importing get_*:

$ time python3 -c 'from cs50 import get_string'

real    0m0.076s
user    0m0.068s
sys     0m0.008s

@kzidane
Copy link
Member Author

kzidane commented Oct 31, 2019

And just for completeness, logger is disabled when using the interpreter (and by default):

$ python3
Python 3.7.3 (default, Oct 28 2019, 16:05:54)
[GCC 7.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from cs50 import SQL
>>> db = SQL('sqlite:///test.db')
>>> db.execute('select 1')
[{'1': 1}]

@kzidane kzidane merged commit 9449e1f into develop Dec 6, 2019
@kzidane kzidane deleted the lazy branch December 6, 2019 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant