How to view print()ed output immediately?

Hello Gentlemen,

I have this simple function:

	def validate(self):
		print("Hello from validate()")

In an instance running not in productive mode (“bench disable-production”) it shows up immediately in the log of the started bench, when the belonging DocType gets validated:

11:06:10 web.1            |  * Debugger is active!
11:06:10 web.1            |  * Debugger PIN: 308-597-710
11:06:28 web.1            | Hello from validate()

When I execute this on an instance with production mode enabled (“bench setup production”) the output is written to frappe-bench/logs/web.log, but only if I issue a “bench restart --supervisor” command.

I guess the print()ed output is buffered somewhere and flushed upon restart.

Is there some kind of configuration to write the output immediately to web.log?
It’s a bit cumbersome to restart the bench just to view some log entries.

I’m using bench 5.7.5 and frappe 13.19.0.

You could add PYTHONUNBUFFERED=1 to web process in /home/frappe/frappe-bench/config/supervisor.conf. It should look something like this

...
[program:frappe-bench-frappe-web]
command=/home/frappe/frappe-bench/env/bin/gunicorn --bind 0.0.0.0:8000 --workers 32 --timeout 120 --worker-tmp-dir /dev/shm frappe.app:application --preload
environment=PYTHONUNBUFFERED=1
priority=4
...

And as usual, after this do

sudo supervisorctl reread
sudo supervisorctl update

Note: bench setup supervisor would rewrite this file.

References:

2 Likes

32 workers ?

Thank you, I did not knew anything about this.