Deploy-ng: stdout is not present in log on Windows?

When I use ‘log_filename’ to log the output of my application, on mac and linux the output of the print() statements is redirected into the log file, on the other hand on Windows only the output of Panda is found in the log.
Is there something special to add or configure to also redirect the application stdout ?

Are you using Python 2 or Python 3? Which version of Panda3D?

Python 2 and Panda3D 1.10.2 (from pip). Good remark, I will try with Python 3.

Yes, use Python 3, please. The problem is that Python 2 uses a different version of the C runtime than Panda3D so Panda cannot control the standard streams.

This will be addressed in 1.10.3 in the below commit, but I still strongly recommend upgrading to Python 3, because I can’t vouch for the robustness of the workaround I’ve implemented.

With Python3 the output of the app is indeed present in the log :slight_smile:

On Mac the default python is still 2.7 and when I pay no attention I run the command with python and not python3. For binary distribution there no added value to provide a build based on Python2 anyway…

Btw, some of the output of Panda3D does not have return lines (which were present when I was using a Python2 build)

Edit: Actually it’s all the output of Panda’s log.

Could it be that you are reading the log file in a tool that only supports Windows newlines, and that Unix newlines are being ignored?

I think I’ll add a big flashing warning when running deploy-ng with Python 2.

That would be great for people like me :slight_smile:

I’m reading the log file using notepad, but thinking about it when I was running the Python2 build there was only the panda log and I guess notepad detected it was Unix-only eol. With the correct log there is a mix of Windows eol and Unix eol and so assumed the former.

Now I observed something weird, the first time I run my application I do get both my log and logs from Panda, but the second time there is only the logs from Panda.

The only difference between the two launches is that my app is caching it’s data and there is a bit more log than the second run, removing the cache restore the app log. So, I guess the output is buffered somewhere but by whom ? and more importantly how to deactivate it or how to flush it ?

Try sys.stdout.flush() and sys.stderr.flush()

I know that :slight_smile:
The problem is when the app crashes early, like in Better detection of not supported gl version? stdout is not flushed when the app crashes. I will try adding sys.stdout.flush() in the periodic task, but I fear it won’t help if something happens at startup or between two flushes.

By “crashes”, do you mean an actual memory fault or a Python exception? I think deploy-stub should be flushing the stdout/stderr streams after an exception. EDIT: or so I thought… I apparently don’t see any explicit flush calls after an exception happens.

You can try seeing if setting the PYTHONUNBUFFERED environment variable to 1 before running the game. If that works, perhaps we need to make a config switch so you can enable this in your application.

Yep, with that variable set to 1 the app log is immediately dumped into output.log and now I can correlate the logs from panda with the log from the app :slight_smile: