Boost your Cloud Foundry Python Edit-Build-Test Speed!
This is a companion post to my earlier one focusing on NodeJS development productivity.
The key discovery is that if you are using Flask as your web server process in your python code(which is pretty much the default approach), you can pass the parameter debug=True when starting the server process.
if __name__ == '__main__': # Run the app, listening on all IPs with our chosen port number # Use this version in production #app.run(host='0.0.0.0', port=port) # Enable server.py reload on changes # This also returns server errors in the html output (security risk) app.run(debug=True, host='0.0.0.0', port=port)
What this does is allow you to edit the server.py file while it is running live on the server and edit it to figure out where your python is going wrong. Every time you save the file, the server detects this and reloads the web server, picking up any changes in the main python file and any imported python files.
This is not a substitute for using a real debugger, but can cut the edit-build-deploy time down from minutes to seconds. This can also be a real development accelerator especially when your target environment can’t be easily replicated locally for testing.
Some things to note. If you make a change that results in a seg-fault or syntax error, the system will reload your code from the blob store into a new instance and you will loose all your changes since the last deploy. To avoid this, use a method to change your code in a git controlled repo folder and then copy the new files into the deployed container. For Cloud Foundry, this is covered in detail in the post mentioned above. For on-pre XS Advanced, I have a similar but different approach that I will cover on a subsequent post. Also I plan on figuring out how to enlist a real python debugger so stay tuned.
That’s it for now. Let me know if you found this helpful.