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 flask server in debug mode breaks hy and drops to Python #329

Closed
Willyfrog opened this issue Nov 17, 2013 · 9 comments
Closed

Comments

@Willyfrog
Copy link
Contributor

Setting a Flask app to run in debug mode breaks hy and drops to python.

Steps to reproduce:
$ hy
hy 0.9.11
=> (import [flask [Flask]])
=> (setv app (Flask "main"))
=> (setv app.debug True)
True
=> (.run app)
* Running on http://127.0.0.1:5000/
* Restarting with reloader
Python 2.7.5 (default, Sep 6 2013, 09:55:21)
[GCC 4.8.1 20130725 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

using kwapply give the same result and running directly without setting debug makes the server run

@paultag
Copy link
Member

paultag commented Nov 17, 2013

So, this happens if you don't use the shim technique that I've used for flask apps - try using a Python shim to import the app and invoke it, so it can re-eval' it and be valid Python :)

Worth looking into better solutions to be sure

@Beluki
Copy link

Beluki commented Jan 17, 2014

Here is a Hy-only workaround:

#!/usr/bin/env hy

(import [flask [Flask]])


;; Change the interpreter executable.
;; Werkzeug will now run Hy instead of Python on restarts.
;; This should work as long as "hy" is in the path.
(import sys)
(setv sys.executable "hy")


(def app (Flask __name__))
(setv app.debug True)

(with-decorator (app.route "/")
    (defn get-index []
        (str "Hello World!")))


;; Run the app, but also restart when this file changes:
(kwapply (app.run) {"extra_files" __file__})

@Kodiologist
Copy link
Member

This still doesn't work in 2017 with Python 3, but it just crashes now:

hy 0.12.1+50.g741b9b9 using CPython(default) 3.6.0 on Linux
=> (import [flask [Flask]])
=> (setv app (Flask "main"))
=> (setv app.debug True)
=> (.run app)
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with stat
/usr/local/bin/python3.6: can't find '__main__' module in '

@Beluki
Copy link

Beluki commented Mar 28, 2017 via email

@refi64
Copy link
Contributor

refi64 commented Mar 28, 2017

:(

@Kodiologist
Copy link
Member

Thanks for letting us know, Marisa, and sorry if I bothered you. Feel free to mute this thread, as mentioned in the email you got from GitHub.

@Beluki
Copy link

Beluki commented Mar 29, 2017 via email

@Kodiologist
Copy link
Member

Actually, the same sequence of calls fails with the same error in Python's own REPL. I'm going to close this until somebody can show an example that works in Python but not a recent version of Hy.

@Beluki
Copy link

Beluki commented Apr 28, 2017 via email

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

No branches or pull requests

5 participants