dave2wave commented on issue #411:
URL: 
https://github.com/apache/tooling-trusted-releases/issues/411#issuecomment-3781528729

   rlimits for memory simply do not work on `macOS`.
   
   ChatGPT wrote a test program for me.
   
   ```
   import sys
   import os
   import psutil
   import resource
   import platform
   import threading
   import time
   
   def set_memory_limit(bytes_limit):
       system = platform.system()
       
       if system == "Linux":
           # RLIMIT_AS works reliably on Linux
           soft, hard = bytes_limit, bytes_limit
           resource.setrlimit(resource.RLIMIT_AS, (soft, hard))
           print(f"[Linux] RLIMIT_AS set to {bytes_limit} bytes")
       
       elif system == "Darwin":
           # macOS: RLIMIT_AS exists but ignored; use psutil monitoring
           print(f"[macOS] RLIMIT_AS is unreliable; using manual monitoring")
           
           def monitor_memory():
               process = psutil.Process(os.getpid())
               while True:
                   mem = process.memory_info().rss
                   if mem > bytes_limit:
                       print(f"[macOS] Memory limit exceeded: {mem} > 
{bytes_limit}")
                       os._exit(1)  # forcefully kill the process
                   time.sleep(0.1)  # check every 100ms
           
           t = threading.Thread(target=monitor_memory, daemon=True)
           t.start()
       else:
           print(f"[{system}] Unsupported OS for memory limiting")
   
   # Example usage
   MEMORY_LIMIT = 2 * 1024**3  # 2 GB
   set_memory_limit(MEMORY_LIMIT)
   
   # Example allocation loop
   lst = []
   try:
       while True:
           lst.append(' ' * 50_000_000)  # allocate 50MB chunks
           print(f"Allocated {len(lst)*50} MB")
   except MemoryError:
       print("Stopped due to memory limit")
   ```
   
   Let's tune for alpine / ubuntu and our containers.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to