Skip to content

Instantly share code, notes, and snippets.

@stickytruth
Last active October 17, 2019 05:08
Show Gist options
  • Select an option

  • Save stickytruth/39c3fa2c88f141a0a26b to your computer and use it in GitHub Desktop.

Select an option

Save stickytruth/39c3fa2c88f141a0a26b to your computer and use it in GitHub Desktop.

Revisions

  1. stickytruth revised this gist Mar 11, 2015. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions example.py
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    """
    Flask's reloader causes kernprof to fail.
    Without the reloader it appears to work.
    """

    from flask import Flask, request
    @@ -20,6 +21,12 @@ def index():


    if __name__ == '__main__':
    # Fails - "debug" enables the reloader
    # app.run('127.0.0.1', 5000, debug=True)

    # Works - "use_debugger" does not enable the reloader
    # app.run('127.0.0.1', 5000, use_debugger=False)

    # Fails
    # app.run('127.0.0.1', 5000, use_reloader=True)

    @@ -29,3 +36,4 @@ def index():
    # Works
    with app.test_client() as c:
    c.get('/')

  2. stickytruth revised this gist Mar 11, 2015. 2 changed files with 18 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions example.py
    Original file line number Diff line number Diff line change
    @@ -29,5 +29,3 @@ def index():
    # Works
    with app.test_client() as c:
    c.get('/')

    # kernprof -l -v example.py
    18 changes: 18 additions & 0 deletions kernprof -l -v example.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    $ kernprof -l -v example.py
    Wrote profile results to example.py.lprof
    Timer unit: 1e-06 s

    Total time: 1.00117 s
    File: example.py
    Function: index at line 13

    Line # Hits Time Per Hit % Time Line Contents
    ==============================================================
    13 @app.route('/')
    14 @profile
    15 def index():
    16 1 1001072 1001072.0 100.0 time.sleep(1)
    17 1 97 97.0 0.0 fn = request.environ.get('werkzeug.server.shutdown')
    18 1 3 3.0 0.0 if fn:
    19 fn()
    20 1 2 2.0 0.0 return 'ok'
  3. stickytruth created this gist Mar 11, 2015.
    33 changes: 33 additions & 0 deletions example.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    """
    Flask's reloader causes kernprof to fail.
    """

    from flask import Flask, request
    import time

    app = Flask(__name__)
    app.testing = True


    @app.route('/')
    @profile
    def index():
    time.sleep(1)
    fn = request.environ.get('werkzeug.server.shutdown')
    if fn:
    fn()
    return 'ok'


    if __name__ == '__main__':
    # Fails
    # app.run('127.0.0.1', 5000, use_reloader=True)

    # Works
    # app.run('127.0.0.1', 5000, use_reloader=False)

    # Works
    with app.test_client() as c:
    c.get('/')

    # kernprof -l -v example.py