Skip to content

Instantly share code, notes, and snippets.

@paolodina
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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
@elijahsgh
Copy link

When using Jython standalone package sys.executable is None - which causes the failure above.
Disabling the reloader resolves the issue ie: app.run(use_reloader=False)

@paolodina
Copy link
Author

Download the installer from http://mvnrepository.com/artifact/org.python/jython-installer and use this Jython instead of standalone. This should fix the issue. If it's not possible, a workaround proposed on #jython (freenode) to make the standalone version work, is adding shell=True to subprocess.call from serving.py in werkzeug and set args[0] to the script name.

@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