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

Is there a way to automatically reload modifications to main.py? #6

Closed
ilpersi opened this issue Jan 18, 2020 · 7 comments · Fixed by #8
Closed

Is there a way to automatically reload modifications to main.py? #6

ilpersi opened this issue Jan 18, 2020 · 7 comments · Fixed by #8
Labels
documentation Improvements or additions to documentation

Comments

@ilpersi
Copy link
Contributor

ilpersi commented Jan 18, 2020

I know that in standard Flask you can do this in the following way:

$ export FLASK_APP=main.py
$ export FLASK_ENV=development
$ flask run

I've tried also with functions-framework with no luck: is there a possible workaround?
Thank you.

@di
Copy link
Member

di commented Jan 18, 2020

Yes, you can use the --debug command line flag or set the DEBUG environment variable to TRUE.

@di di added the documentation Improvements or additions to documentation label Jan 18, 2020
@ilpersi
Copy link
Contributor Author

ilpersi commented Jan 19, 2020

I saw the --debug TRUE switch in #5 and used it to debug my functions; it does not automatically reload the main.py after I modify it: I have to stop function-framework and start it again

@di
Copy link
Member

di commented Jan 20, 2020

Can you give us some more details about how you're trying to run the functions-framework? The following works for me

$ cat main.py
def hello(request):
    return "Hello world!"

$ functions-framework --target hello --debug TRUE
 * Serving Flask app "hello" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on http://0.0.0.0:8080/ (Press CTRL+C to quit)
 * Restarting with fsevents reloader
 * Debugger is active!
 * Debugger PIN: 137-358-281

<wrote to main.py>

 * Detected change in '/Users/dustiningram/main.py', reloading
 * Detected change in '/Users/dustiningram/main.py', reloading
 * Restarting with fsevents reloader
 * Debugger is active!
 * Debugger PIN: 137-358-281

$ flask --version
Python 3.7.4
Flask 1.1.1
Werkzeug 0.16.0

@ilpersi
Copy link
Contributor Author

ilpersi commented Jan 20, 2020

Hi Dustin, here is a video of what I am doing: https://drive.google.com/file/d/1BJx4Bmc2YN4sgLTKDRSbqo-EdX1TZomj/preview

Is there any other detail that can help you?

@di
Copy link
Member

di commented Jan 20, 2020

Hi @ilpersi, thanks for the very detailed video! One difference is that Flask/Werkzeug is using the "stat" reloader on your machine, but I'm using "fsevents" which comes from the watchdog package.

It seems like what Flask uses varies from one platform to another. Could you try installing watchdog in your environment and see if that helps?

Also if you could include the output of flask --version that'd be great. Thanks!

@ilpersi
Copy link
Contributor Author

ilpersi commented Jan 21, 2020

@di installing watchdog solves the issue! 🔝 👍

Here is my flask --version

Python 3.7.4
Flask 1.1.1
Werkzeug 0.16.0

I think that Flask version is also something that deserves more documentation: to stick with the cloud functions runtime I originally installed 1.0.2. and I updated to 1.1.1 after you posted your flask --version as an attempt to fix the issue.

The video in the previous comment is shot with 1.1.1 and installing watchdog fixes the issue both with 1.0.2 and 1.1.1 (I tested them both).

Thank you very much.

ilpersi added a commit to ilpersi/functions-framework-python that referenced this issue Jan 22, 2020
@di di closed this as completed in #8 Jan 30, 2020
di added a commit that referenced this issue Jan 30, 2020
* Adding watchdog dependency (#6).

* Don't pin to a specific watchdog version

* Require a more modern version of watchdog

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
@di
Copy link
Member

di commented Feb 6, 2020

FYI, once #15 is released, this will just be a flag (--debug) instead of an option (--debug TRUE).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants