[GRASS-git] [OSGeo/grass] 2b2096: grass.gunittest: Solve ResourceWarning in gs.parse...

Edouard Choinière noreply at github.com
Tue Aug 12 16:34:58 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/OSGeo/grass
  Commit: 2b2096424495456fa71154b8771338b10a6e0c75
      https://github.com/OSGeo/grass/commit/2b2096424495456fa71154b8771338b10a6e0c75
  Author: Edouard Choinière <27212526+echoix at users.noreply.github.com>
  Date:   2025-08-12 (Tue, 12 Aug 2025)

  Changed paths:
    M python/grass/script/core.py

  Log Message:
  -----------
  grass.gunittest: Solve ResourceWarning in gs.parser() coming from sys.stdout (#6196)

The note at the end of [`sys.stdout`'s docs](https://docs.python.org/3/library/sys.html#sys.stdout) mentions that writing binary data to the standard streams should use the underlying binary buffer object. However, that file might be replaced by a file-like object that doesn't support the buffer attribute.

So, inspired by [the code example for `sys.displayhook`](https://docs.python.org/3.13/library/sys.html#sys.displayhook), use the binary buffer object if available or simply write the encoded text otherwise.

This solves multiple ResourceWarnings found in tests that could be traced back to this when enabling python tracemalloc as written in the warning messages. One of the ways is to set the env var `PYTHONTRACEMALLOC` to the number of frames to keep. So, `export PYTHONTRACEMALLOC=15` is enough.



To unsubscribe from these emails, change your notification settings at https://github.com/OSGeo/grass/settings/notifications


More information about the grass-commit mailing list