pallets / flask

The Python micro framework for building web applications.
https://flask.palletsprojects.com
BSD 3-Clause "New" or "Revised" License
68.01k stars 16.21k forks source link

Unable to unlock Console after file reloading in debug mode #4932

Closed Young-Lord closed 1 year ago

Young-Lord commented 1 year ago

Content

Unable to unlock Console after file reloading in debug mode

Reproduce

from flask import request,Flask
app=Flask(__name__)
@app.route('/err')
def err():
    return 1/0
app.run(debug=True)
  1. Save the code to a file, run it
  2. Open http://127.0.0.1:5000/err for the error page
  3. Make some minor changes(e.g., spaces, comments) to the file and save, trigger a hot reload
  4. Don't refresh the page opened before, click Open an interactive python shell in this frame at the right of return 1/0.
  5. Enter any PIN, got an Error: Could not verify PIN. Network error?

Expect

the PIN verification should behave properly.

Traceback

D:\>python flt.py
 * Serving Flask app 'flt'
 * Debug mode: on
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on http://127.0.0.1:5000
Press CTRL+C to quit
 * Restarting with watchdog (windowsapi)
 * Debugger is active!
 * Debugger PIN: 974-140-517
127.0.0.1 - - [31/Dec/2022 13:10:25] "GET /err HTTP/1.1" 500 -
Traceback (most recent call last):
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\app.py", line 2548, in __call__
    return self.wsgi_app(environ, start_response)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\app.py", line 2528, in wsgi_app
    response = self.handle_exception(e)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\app.py", line 2525, in wsgi_app
    response = self.full_dispatch_request()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\app.py", line 1822, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\app.py", line 1820, in full_dispatch_request
    rv = self.dispatch_request()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\app.py", line 1796, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "D:\flt.py", line 5, in err
    return 1/0
ZeroDivisionError: division by zero
127.0.0.1 - - [31/Dec/2022 13:10:26] "GET /err?__debugger__=yes&cmd=resource&f=style.css HTTP/1.1" 200 -
127.0.0.1 - - [31/Dec/2022 13:10:26] "GET /err?__debugger__=yes&cmd=resource&f=debugger.js HTTP/1.1" 200 -
127.0.0.1 - - [31/Dec/2022 13:10:26] "GET /err?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1" 200 -
127.0.0.1 - - [31/Dec/2022 13:10:26] "GET /err?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1" 304 -
 * Detected change in 'D:\\flt.py', reloading
 * Detected change in 'D:\\flt.py', reloading
 * Restarting with watchdog (windowsapi)
 * Debugger is active!
 * Debugger PIN: 974-140-517
127.0.0.1 - - [31/Dec/2022 13:10:42] "GET /err?__debugger__=yes&cmd=printpin&s=4EbBYjOKMpzMFl2eiZSL HTTP/1.1" 500 -
Traceback (most recent call last):
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\app.py", line 2548, in __call__
    return self.wsgi_app(environ, start_response)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\app.py", line 2528, in wsgi_app
    response = self.handle_exception(e)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\app.py", line 2525, in wsgi_app
    response = self.full_dispatch_request()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\app.py", line 1822, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\app.py", line 1820, in full_dispatch_request
    rv = self.dispatch_request()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\app.py", line 1796, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "D:\flt.py", line 5, in err
    return 1/0
ZeroDivisionError: division by zero
127.0.0.1 - - [31/Dec/2022 13:10:44] "GET /err?__debugger__=yes&cmd=pinauth&pin=http%3A%2F%2F127.0.0.1%3A5000%2Ferr&s=4EbBYjOKMpzMFl2eiZSL HTTP/1.1" 500 -
Traceback (most recent call last):
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\app.py", line 2548, in __call__
    return self.wsgi_app(environ, start_response)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\app.py", line 2528, in wsgi_app
    response = self.handle_exception(e)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\app.py", line 2525, in wsgi_app
    response = self.full_dispatch_request()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\app.py", line 1822, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\app.py", line 1820, in full_dispatch_request
    rv = self.dispatch_request()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\app.py", line 1796, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "D:\flt.py", line 5, in err
    return 1/0
ZeroDivisionError: division by zero

Environment:

davidism commented 1 year ago

When the application reloads, it is a new environment, it doesn't have references to old frames anymore.