-1

In an application that I'm writing the user can provide a class which will then be trial runned in a thread to see if it throws any exceptions.

However, I want to suppress any printing by that class in that thread. I know how to do this based on this solution, but my question is if this will block the printing for the whole application? So when this thread is running can other threads still print to the console?

EDIT: Adding example code from that solutions answer for your convenience:

import os, sys

class HiddenPrints:
    def __enter__(self):
        self._original_stdout = sys.stdout
        sys.stdout = open(os.devnull, 'w')

    def __exit__(self, exc_type, exc_val, exc_tb):
        sys.stdout.close()
        sys.stdout = self._original_stdout

with HiddenPrints():
    print("This will not be printed")

print("This will be printed as before")
rongard
  • 89
  • 7
  • Think about it: If you redirect standard output to null (does not matter from which thread), how shall other threads still be able to print to the standard output? – Markus Safar Nov 02 '22 at 05:48
  • 1
    Thanks, just wanted to confirm this. For beginners it might not be so obvious. I would have asked this as a comment in the referenced solution, but I did not have enough reputation do add comments there. – rongard Nov 02 '22 at 10:01

1 Answers1

1

So as @Markus Safar as pointed out then no, other threads will no be able to print to console as well.

rongard
  • 89
  • 7