Skip to content

Instantly share code, notes, and snippets.

@paolodina
Last active August 29, 2015 14:01
Show Gist options
  • Save paolodina/b98c3f3a159024584e13 to your computer and use it in GitHub Desktop.
Save paolodina/b98c3f3a159024584e13 to your computer and use it in GitHub Desktop.
jython 2.7b2 and flask reload - subprocess issue
# hello.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return "Hellox, World!"
if __name__ == '__main__':
app.debug = True # <------ removing this everything works fine
app.run()
(venv)paolo@tk:$ java -jar jython-standalone-2.7-b2.jar app/hello.py
* Running on http://127.0.0.1:5000/
* Restarting with reloader
Traceback (most recent call last):
File "app/hello.py", line 10, in <module>
app.run()
File "/home/paolo/jdevel/golap-workspace/venv/project/Lib/flask/app.py", line 772, in run
run_simple(host, port, self, **options)
File "/home/paolo/jdevel/golap-workspace/venv/project/Lib/werkzeug/serving.py", line 708, in run_simple
run_with_reloader(inner, extra_files, reloader_interval)
File "/home/paolo/jdevel/golap-workspace/venv/project/Lib/werkzeug/serving.py", line 617, in run_with_reloader
sys.exit(restart_with_reloader())
File "/home/paolo/jdevel/golap-workspace/venv/project/Lib/werkzeug/serving.py", line 617, in run_with_reloader
sys.exit(restart_with_reloader())
File "/home/paolo/jdevel/golap-workspace/venv/project/Lib/werkzeug/serving.py", line 601, in restart_with_reloader
exit_code = subprocess.call(args, env=new_environ)
File "/home/paolo/jdevel/golap-workspace/venv/project/jython-standalone-2.7-b2.jar/Lib/subprocess.py", line 500, in call
File "/home/paolo/jdevel/golap-workspace/venv/project/jython-standalone-2.7-b2.jar/Lib/subprocess.py", line 830, in __init__
File "/home/paolo/jdevel/golap-workspace/venv/project/jython-standalone-2.7-b2.jar/Lib/subprocess.py", line 1309, in _execute_child
TypeError: args must contain only strings
@transistor1
Copy link

Created a workaround for the standalone here: https://github.com/transistor1/werkzeug, using paolodina's serving.py method. Checks if the platform is Jython before using. Seems to work on both Linux and Windows, though not tested extensively. You can just replace your serving.py file with this one https://github.com/transistor1/werkzeug/blob/master/werkzeug/serving.py

@transistor1
Copy link

Note you also need to add -Dpython.cachedir.skip=false to your Java command line, or Jython won't be able to find java.lang.management:

java -Dpython.cachedir.skip=false -jar /path/to/jython/jarfile.jar flask_file_to_run.py

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