Skip to content

Fix subprocess ResourceWarning (#84), modernize Python, fix broken README links#88

Merged
giswqs merged 1 commit intomasterfrom
fix/subprocess-resource-warnings-and-modernization
Jan 31, 2026
Merged

Fix subprocess ResourceWarning (#84), modernize Python, fix broken README links#88
giswqs merged 1 commit intomasterfrom
fix/subprocess-resource-warnings-and-modernization

Conversation

@giswqs
Copy link
Member

@giswqs giswqs commented Jan 31, 2026

Summary

This PR addresses issue #84 (subprocess ResourceWarning) and includes several code quality improvements.

🐛 Bug Fix — Subprocess ResourceWarning (Fixes #84)

All subprocess.Popen calls now use context managers (with statements), which ensures proper cleanup and eliminates ResourceWarning: subprocess N is still running when running with pytest -Werror.

Before: 17 bare Popen() calls across set_verbose_mode, set_compress_rasters, set_max_procs, run_tool, help, license, version, tool_help, tool_parameters, toolbox, view_code, and list_tools.

After: Two reusable helper methods handle all subprocess execution:

  • _run_process(args, callback) — streams output line-by-line with cancel support (used by run_tool, set_verbose_mode, etc.)
  • _run_process_output(args) — captures and returns full output as a string (used by help, version, license, etc.)
  • _popen_kwargs() — consolidates common Popen arguments and Windows startupinfo logic (was duplicated 8+ times)

🔧 Python Modernization

  • Remove from __future__ import print_function (Python 2 compatibility, unnecessary since Python 3 is required)
  • Replace class WhiteboxTools(object)class WhiteboxTools (new-style class syntax)
  • Convert .format() string formatting to f-strings in core methods
  • Replace == True comparisons with idiomatic boolean checks (if self.start_minimized)
  • Fix mutable default argument: list_tools(keywords=[])keywords=None
  • Fix incorrect docstring on set_max_procs (was a copy of set_compress_rasters)

📝 README Fixes

  • Replace 5 broken gishub.org short links (all returning HTTP 404) with direct URLs to mybinder.org and GitHub
  • Update pepy.tech download badge to current format (/badge//pepy/dt/)

📦 setup.py Updates

  • Update Python version classifiers from 3.4–3.6 to 3.9–3.13
  • Update development status from "Pre-Alpha" to "Beta" (the package has 405+ stars and is on conda-forge)

Net Impact

3 files changed, 130 insertions(+), 370 deletions(-)

240 lines of duplicated subprocess boilerplate removed.

Fixes:
- Fix ResourceWarning from unclosed subprocess (fixes #84): Use Popen as
  context manager via new _run_process() and _run_process_output() helpers.
  All 17 bare Popen calls now properly use 'with' statements.
- Extract common Popen kwargs into _popen_kwargs() to eliminate duplicated
  Windows startupinfo logic across every method.

Python modernization:
- Remove 'from __future__ import print_function' (Python 2 compat, unnecessary)
- Replace 'class WhiteboxTools(object)' with 'class WhiteboxTools' (new-style)
- Convert .format() to f-strings in core methods
- Replace '== True' comparisons with idiomatic boolean checks
- Fix mutable default argument: list_tools(keywords=[]) -> keywords=None
- Fix incorrect docstring on set_max_procs (was copy of set_compress_rasters)

README fixes:
- Replace 5 broken gishub.org short links (all returning 404) with direct URLs
- Update pepy.tech badge to current format

setup.py:
- Update Python version classifiers from 3.4-3.6 to 3.9-3.13
- Update development status from Pre-Alpha to Beta
@giswqs giswqs merged commit 1fcd8d2 into master Jan 31, 2026
8 checks passed
@giswqs giswqs deleted the fix/subprocess-resource-warnings-and-modernization branch January 31, 2026 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ResourceWarning: subprocess n is still running

1 participant