# Suppress/Catch warning and error messages in python

**URL:** <https://forum.aousd.org/t/suppress-catch-warning-and-error-messages-in-python/1926>\
**Category:** USD\
**Created:** [October 17, 2024, 8:38pm UTC](https://forum.aousd.org/t/suppress-catch-warning-and-error-messages-in-python/1926 "2024-10-17T20:38:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Truant](https://avatars.discourse-cdn.com/v4/letter/t/c6cbf5/32.png) [@Truant](https://forum.aousd.org/u/Truant)\
**Post date:** [October 17, 2024, 8:38pm UTC](https://forum.aousd.org/t/suppress-catch-warning-and-error-messages-in-python/1926/1 "2024-10-17T20:38:27Z")

</div>

Hello:  
Is there a way to suppress warning messages in the terminal with either code or environment variable? I see there is a TfErrorMark that seems to allow me to catch error messages between points but I don’t seem to see a python binding for it. (22.05) Thank you!

---

<div class="post-metadata">

**Author:** ![asluk](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.aousd.org/asluk/32/771_2.png) [@asluk](https://forum.aousd.org/u/asluk)\
**Post date:** [October 17, 2024, 9:49pm UTC](https://forum.aousd.org/t/suppress-catch-warning-and-error-messages-in-python/1926/2 "2024-10-17T21:49:59Z")

</div>

You can write your own diagnostic delegate to filter warnings and errors–  
see [Universal Scene Description: pxr/usd/usdUtils/coalescingDiagnosticDelegate.h File Reference](https://openusd.org/release/api/coalescing_diagnostic_delegate_8h.html) and  
[OpenUSD/pxr/usd/usdUtils/testenv/testUsdUtilsCoalescingDiagnosticDelegate.py at release · PixarAnimationStudios/OpenUSD · GitHub](https://github.com/PixarAnimationStudios/OpenUSD/blob/release/pxr/usd/usdUtils/testenv/testUsdUtilsCoalescingDiagnosticDelegate.py)

---

<div class="post-metadata">

**Author:** ![spiff](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.aousd.org/spiff/32/22_2.png) [@spiff](https://forum.aousd.org/u/spiff)\
**Post date:** [October 18, 2024, 12:02am UTC](https://forum.aousd.org/t/suppress-catch-warning-and-error-messages-in-python/1926/3 "2024-10-18T00:02:28Z")

</div>

In fact, the delegate Aaron identifies can be used to suppress output, instead of coalescing it.

---

<div class="post-metadata">

**Author:** ![Truant](https://avatars.discourse-cdn.com/v4/letter/t/c6cbf5/32.png) [@Truant](https://forum.aousd.org/u/Truant)\
**Post date:** [October 18, 2024, 11:44am UTC](https://forum.aousd.org/t/suppress-catch-warning-and-error-messages-in-python/1926/4 "2024-10-18T11:44:35Z")

</div>

Thank you both! I will look into the delegate.

---

<div class="post-metadata">

**Author:** ![nvmkuruc](https://avatars.discourse-cdn.com/v4/letter/n/76d3ee/32.png) [@nvmkuruc](https://forum.aousd.org/u/nvmkuruc)\
**Post date:** [October 22, 2024, 5:21pm UTC](https://forum.aousd.org/t/suppress-catch-warning-and-error-messages-in-python/1926/5 "2024-10-22T17:21:13Z")

</div>

As an alternative, on this thread we suggested that perhaps `TF_WARN` should integrate with the `warning` module via `PyError_Warn`. That would surface OpenUSD warnings as native python warnings (similar to how OpenUSD errors are surfaced as pyton exceptions) without having to rely on delegates to do filtering.

[Integrating USD Tf.Warn with Python logging.Logger - Community / USD - Alliance for OpenUSD (aousd.org)](https://forum.aousd.org/t/integrating-usd-tf-warn-with-python-logging-logger/1221/3)
