0

I have a weird behaviour using a Python application, (running under supervisor), that relies on a C library to initialize a component.

My problem is that i cannot see the output printed by this C library when i call a function there.

All the output in the application is managed with the logging module, and supervisor redirects it to a single log file.

So i thought this was just flush problem, and I tried the following:

lib.init_func()
sys.stdout.flush()
sys.stderr.flush()

But it doesn't work. I cannot see my printf() in the log file.

Also, I noticed that if i try to restart the application: sudo supervisorctl restart all The C library output gets finally flushed at the end of the log file !

Finally, setting PYTHONUNBUFFERED=1 in supervisorctl makes it works, but i don't want to run my program unbuffered for performance issues.

--> Can someone explain why using sys.stdout.flush() after the call to the C library is not flushing it's output on my log file ?

Thanks !

Wenzel
  • 147
  • 1
  • 14
  • Possible duplicate of [In python, how to capture the stdout from a c++ shared library to a variable](https://stackoverflow.com/questions/24277488/in-python-how-to-capture-the-stdout-from-a-c-shared-library-to-a-variable) – Brett7533 Feb 26 '18 at 15:42
  • Thank you, this is interesting ! – Wenzel Feb 27 '18 at 16:23

0 Answers0