Reloading python files in production setup of bench without running "bench restart"

While testing code on a Frappe Production setup, modifications of python code inside an app don’t take effect until you run “bench restart”. Bench restart usually takes around 10-13 seconds.

Me and my coworker discovered that by killing gunicorn (pkill gunicord), the python code gets reloaded and gunicorn process gets restarted almost instantly, so we made a small script that watches for changes in python files and automatically triggers gunicord restart whenever a python file changes. This speeds up development process and makes it possible to modify python code in production without 13 second downtime caused by running “bench restart”.

Here is the source code

I’m not sure if there’s a cleaner and more correct way of doing this, so please let us know if you have a better alternative.

@KostyaKow if you are developing, use bench start and not gunicorn for testing. bench start will automatically reload when you change a file.

I have a virtualbox vm for development and mount a shared folder like this

sudo mount -t vboxsf vagrant apps/ -o uid=`id -u vagrant`,gid=`id -g vagrant`

but it seems the file system events when changing a file aren’t triggered, I have to manually stop and start bench everytime for the .pyc files to be regenerated. Have to call bench build manually all the time, too.

Do you happen to know whether I have to add another option to the mount command or if I can modify the file change listen command somehow?
Or maybe just tell me what tools and commands listen for the file change events so I could dig around at their respective repositories.

for production?