From 5a350aa07ab33c063d10bee1e4567609ff4debad Mon Sep 17 00:00:00 2001 From: Wendy Wang Date: Wed, 9 Oct 2024 15:06:29 +0200 Subject: [PATCH] Use the same locale regardless of system locale Ensures standard number formatting. --- evennia/commands/default/system.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/evennia/commands/default/system.py b/evennia/commands/default/system.py index ceecfd27f3..a02449555b 100644 --- a/evennia/commands/default/system.py +++ b/evennia/commands/default/system.py @@ -13,6 +13,7 @@ import traceback import django import evennia +import subprocess import twisted from django.conf import settings from evennia.accounts.models import AccountDB @@ -862,16 +863,26 @@ class CmdServerLoad(COMMAND_DEFAULT_CLASS): if not _RESOURCE: import resource as _RESOURCE + env = os.environ.copy() + env["LC_NUMERIC"] = "C" # use default locale instead of system locale loadavg = os.getloadavg()[0] - rmem = ( - float(os.popen("ps -p %d -o %s | tail -1" % (pid, "rss")).read()) / 1000.0 - ) # resident memory - vmem = ( - float(os.popen("ps -p %d -o %s | tail -1" % (pid, "vsz")).read()) / 1000.0 - ) # virtual memory - pmem = float( - os.popen("ps -p %d -o %s | tail -1" % (pid, "%mem")).read() - ) # % of resident memory to total + + # Helper function to run the ps command with a modified environment + def run_ps_command(command): + result = subprocess.run( + command, shell=True, env=env, stdout=subprocess.PIPE, text=True + ) + return result.stdout.strip() + + # Resident memory + rmem = float(run_ps_command(f"ps -p {pid} -o rss | tail -1")) / 1000.0 + + # Virtual memory + vmem = float(run_ps_command(f"ps -p {pid} -o vsz | tail -1")) / 1000.0 + + # Percentage of resident memory to total + pmem = float(run_ps_command(f"ps -p {pid} -o %mem | tail -1")) + rusage = _RESOURCE.getrusage(_RESOURCE.RUSAGE_SELF) if "mem" in self.switches: