How to suppress warning output ?

I built a DXF file converter application using KLayout python module. It works quite well. But it produces warning messages saying "Warning: Entity VIEWPORT not supported - ignored.". And I just want to ignore and hide them from users. Is there any way to suppress these warning messages without re-building python module?

Comments

  • No, sorry. Currently these warnings are unconditionally sent to stdout for the Python module. The only way to suppress them is to redirect stdout (temporarily) somewhere else.

    But I'd say these warnings are an indication that DXF is not fully implemented. Please take this message seriously. DXF is not well defined and KLayout's module implements a subset only and even for that I'm not sure about the quality. Unless you know what you're doing, I do not advise to use it.

    Matthias

  • Thanks for detailed reply. I tried to redirect stdout without success. Using contextlib, I can only suppress print("readFile"). Viewport-related warning messages are NOT suppressed. Strange...

    import pya
    from contextlib import contextmanager
    import sys, os
    
    @contextmanager
    def suppress_stdout():
        with open(os.devnull, "w") as devnull:
            old_stdout = sys.stdout
            sys.stdout = devnull
            try:  
                yield
            finally:
                sys.stdout = old_stdout
    
    def readFile():
        print("readFile")
        layout = pya.Layout()
        load_options = pya.LoadLayoutOptions()
        load_options.dxf_polyline_mode=3
        load_options.dxf_text_scaling=100
        load_options.dxf_circle_points=64
        load_options.dxf_dbu=0.01
        load_options.dxf_unit=1
        layout.read("sample.dxf", load_options)
    
    with suppress_stdout():
        readFile()
    
  • No, I'm sorry. The message is not printed by Python, hence you cannot redirect stdout this way.

    Currently there is no way to redirect or suppress log output from Python. You can only run the DXF reader is a separate process and redirect that process' stdout.

    I have created a ticket for this, but cannot promise a quick solution: https://github.com/KLayout/klayout/issues/1138

    Matthias

  • Ah.. I see. The new ticket creation is really appreciated.

Sign In or Register to comment.