Use the same locale regardless of system locale

Ensures standard number formatting.
This commit is contained in:
Wendy Wang 2024-10-09 15:06:29 +02:00
parent fd05fe4c02
commit 5a350aa07a

View file

@ -13,6 +13,7 @@ import traceback
import django import django
import evennia import evennia
import subprocess
import twisted import twisted
from django.conf import settings from django.conf import settings
from evennia.accounts.models import AccountDB from evennia.accounts.models import AccountDB
@ -862,16 +863,26 @@ class CmdServerLoad(COMMAND_DEFAULT_CLASS):
if not _RESOURCE: if not _RESOURCE:
import resource as _RESOURCE import resource as _RESOURCE
env = os.environ.copy()
env["LC_NUMERIC"] = "C" # use default locale instead of system locale
loadavg = os.getloadavg()[0] loadavg = os.getloadavg()[0]
rmem = (
float(os.popen("ps -p %d -o %s | tail -1" % (pid, "rss")).read()) / 1000.0 # Helper function to run the ps command with a modified environment
) # resident memory def run_ps_command(command):
vmem = ( result = subprocess.run(
float(os.popen("ps -p %d -o %s | tail -1" % (pid, "vsz")).read()) / 1000.0 command, shell=True, env=env, stdout=subprocess.PIPE, text=True
) # virtual memory )
pmem = float( return result.stdout.strip()
os.popen("ps -p %d -o %s | tail -1" % (pid, "%mem")).read()
) # % of resident memory to total # 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) rusage = _RESOURCE.getrusage(_RESOURCE.RUSAGE_SELF)
if "mem" in self.switches: if "mem" in self.switches: