Skip to content

Commit

Permalink
Fix: File was only closed lazily by garbage collector
Browse files Browse the repository at this point in the history
Problem: Reading a file using `f.open().read()` keeps the file open until the garbage collector deletes the variable.

Since this uses Pathlib already, using `Path(...).read_text()` is cleaner and does not depend on the opening mode being `r`.

A file with no content could not be distinguished from a missing file. Instead, this changes the behaviour to return None when the file is missing instead of an empty string.
  • Loading branch information
hoh committed May 30, 2024
1 parent cc3f292 commit 2c2d3f8
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/aleph/vm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ def is_command_available(command):
return False


def check_system_module(module_path: str) -> str:
def check_system_module(module_path: str) -> Optional[str]:
p = Path("/sys/module") / module_path
if not p.exists():
return ""
return p.open().read().strip()
return None
return p.read_text().strip()


def fix_message_validation(message: dict) -> dict:
Expand Down

0 comments on commit 2c2d3f8

Please sign in to comment.