Skip to content

vector: close files and pipes in v.rast.stats, v.db.*, v.report and v.in.e00 - #8126

Closed
abhinav-phi wants to merge 1 commit into
OSGeo:mainfrom
abhinav-phi:vector-close-files
Closed

abhinav-phi wants to merge 1 commit into
OSGeo:mainfrom
abhinav-phi:vector-close-files

Conversation

@abhinav-phi

Copy link
Copy Markdown

Description

Close files and pipes that these vector tools open and never close:

  • v.rast.stats: close the gs.pipe_command() stdout in get_nr_of_categories() and perform_stats(); remove the unused nuldev and its os import.
  • v.db.droptable: use a context manager for the /dev/null handle.
  • v.db.univar, v.db.reconnect.all: close the module-level /dev/null handle in a finally.
  • v.report: close the four gs.pipe_command() stdouts and the /dev/null handle.
  • v.in.e00: close the /dev/null handle after use.

Motivation and context

Part of #8122. With PYTHONDEVMODE=1 these tools report unclosed files and pipes.

How has this been tested?

The reproducers from #8122, run with PYTHONDEVMODE=1:

  • v.rast.stats: before the change v.rast.stats.py:212: ResourceWarning: unclosed file <_io.BufferedReader name=5> plus a /dev/null warning; after the change neither, and the r_average column is still created.
  • v.db.droptable: before v.db.droptable.py:125: ResourceWarning: unclosed file <_io.TextIOWrapper name='/dev/null' ...>; after the change no warning.

Tested against GRASS 7.8 from the system package because this machine cannot build main (needs GDAL 3.7+, has 3.4). The changed code paths are version independent.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist

AI assistance was used to prepare this change and the test results above.

….in.e00

Close gs.pipe_command() stdout and the /dev/null handles these scripts open, so running them with PYTHONDEVMODE=1 no longer reports ResourceWarning. The unused nuldev in v.rast.stats is removed with its os import.
@github-actions github-actions Bot added vector Related to vector data processing Python Related code is in Python module labels Oct 28, 2026
@echoix

echoix commented Oct 28, 2026

Copy link
Copy Markdown
Member

Testing against grass 7.8 is not valid at all. It’s really really old and different than the state we are now, code quality-wise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module Python Related code is in Python vector Related to vector data processing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants