Automatic compilation of py-files on Tryton server

Hi,
We have two Tryton servers. One of them automatically compiles py-files after they are changed on this server. On the second server, py-files are not compiled, but we can see these messages:

INFO:werkzeug: * Detected change in '.../file.py', reloading
INFO:werkzeug: * Restarting with stat

What does automatic compilation of py-files depend on?

You should execute the werkzeug server with the --dev flag.

trytond --dev will restart the server once a file is changed and reload the changes.
trytond won’t restart if any file is changed and keep running the loaded version unless you restart it explicitly.

Both servers are started with trytond --dev. Both servers restart after changing py-files. On one server the py-files are automatically compiled, but on the second server they are not.

This is Python feature. I guess the user running trytond has no write-access on the proper folder to store compiled files.
But any way it is a bad idea to run in production with the werkzeug development server and even worse with the development mode.
It is also a bad idea if the user running the server has write-access to the code source as this remove a layer of security protection in case of attack.

Finally you can use compileall to compile in advance the Python files.

1 Like

This is not about users, but about developers. All developers have write permissions to folders for compiled files.

But any way it is a bad idea to run in production with the werkzeug development server and even worse with the development mode.

We are talking about virtual servers for developers.

Finally you can use compileall to compile in advance the Python files.

We do exactly that. But we noticed that one developer does not need to run compileall.

Оn the first server the owner and group tryton had write permissions to the folders __pycache__. But on the second server, only the owner had write permissions to these folders.
However, it turned out that automatic compilation is performed only if there are no errors in py-files. After any error, you have to run compileall. It would be cool if automatic compilation was always performed, even after fixing errors in py-files.

Does anyone know why werkzeug detects changes in py-files if there are no errors in them, but does not do so after detecting some error and fixing it?

This could explain Reloader still does not work after syntax error · Issue #594 · pallets/werkzeug · GitHub
Otherwise you should report a bug to werkzeug.

1 Like

Yes, after fixing the syntax error, you will have to restart the server manually. Then the watchdog reloader works again. Many thanks for the good advice.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.