Skip to content

Commit

Permalink
added test_memory()
Browse files Browse the repository at this point in the history
  • Loading branch information
JHalbauer committed Mar 20, 2024
1 parent fc1ded9 commit c6e6b82
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/grass_gis_helpers/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,23 @@ def free_ram(unit, percent=100):
return int(round(memory_gb_percent))
else:
grass.fatal(f"Memory unit {unit} not supported")



def test_memory(memory_string):
"""Function returns available memory.
Args:
memory_string(string): string from standard memory input option
Returns:
memory(int): available memory to use"""
# check memory
memory = int(memory_string)
ram = free_ram("MB", 100)
if ram < memory:
grass.warning(
_(f"Using {memory} MB but only {ram} MB RAM available.")
)
grass.warning(_(f"Set used memory to {ram} MB."))
return ram
else:
return memory

0 comments on commit c6e6b82

Please sign in to comment.