Python fork: 'Cannot allocate memory' if process consumes more than 50% avail. memory
Python fork: 'Cannot allocate memory' if process consumes more than 50% avail. memory I encountered a memory allocation problem when forking processes in Python. I know the issue was already discussed in some other posts here, however I couldn't find a good solution in any of them. Here is a sample script illustrating the Problem: import os import psutil import subprocess pid = os.getpid() this_proc = psutil.Process(pid) MAX_MEM = int(psutil.virtual_memory().free*1E-9) # in GB def consume_memory(size): """ Size in GB """ memory_consumer = while get_mem_usage() < size: memory_consumer.append(" "*1000000) # Adding ~1MB return(memory_consumer) def get_mem_usage(): return(this_proc.memory_info()[0]/2.**30) def get_free_mem(): return(psutil.virtual_memory().free/2.**30) if __name__ == "__main__": for i in range(1, MAX_MEM): consumer = consume_memory(i) mem_usage = get_mem_usa...