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

Running a simple Flask app will not work because an older run is cached somehow. #3826

Closed
enjoysmath opened this issue Nov 4, 2020 · 2 comments

Comments

@enjoysmath
Copy link

enjoysmath commented Nov 4, 2020

Expected Behavior

For updates of the code including favicon and index.html to be shown when I hit run in my IDE again (Wingware, but same problem at command line).

# Minimal example is any Flask app

Actual Behavior

Running the app renders the same app I first ran today, namely:
https://github.com/helloflask/calculator

Changing the page title in index.html or the favicon does not get reflected when the app is run.

Environment

  • Python version: Python 3.8.3
  • Flask version: Version: 1.1.2
  • Werkzeug version: Version: 1.0.1

I've made the following script in order to try to both kill the server and delete any .pyc caching that might be causing the problem. For Windows only:

kill_server.py:

import os
import subprocess
import re

port = 5000
host = '127.0.0.1'
cmd_newlines = r'\r\n'

host_port = host + ':' + str(port)
pid_regex = re.compile(r'[0-9]+$')

netstat = subprocess.run(['netstat', '-n', '-a', '-o'], stdout=subprocess.PIPE)  
# Doesn't return correct PID info without precisely these flags
netstat = str(netstat)
lines = netstat.split(cmd_newlines)

for line in lines:
    if host_port in line:
        pid = pid_regex.findall(line)
        if pid:
            pid = pid[0]
            os.system('taskkill /F /PID ' + str(pid))
        
# And finally delete the .pyc cache
os.system('del /S *.pyc')

The problem remains dispite manually doing the above taskkills and deleting .pyc files by hand or running kill_server.py. Therefore, there's something going on in Flask that is causing the old app to be run (it's cached or something...)

Please help! I really want to make a calculator in Flask, not CherryPy.

I've tried "Clear Browsing Data > Clear Images & Files / Cookies" in Chrome, on Windows 10. Same issue.

@enjoysmath
Copy link
Author

Okay, maybe clear browsing data did work, because it's showing the new favicon now. But it didn't work immediately after doing that. Anyhow... thanks for any advice you have.

@davidism
Copy link
Member

davidism commented Nov 4, 2020

It's a browser caching issue. Better defaults will be used in Flask 2.0 with pallets/werkzeug#1886.

@davidism davidism closed this as completed Nov 4, 2020
@pallets pallets locked as resolved and limited conversation to collaborators Nov 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants