Python subprocess.Popen erroring with OSError: [Errno 12] Cannot allocate memory after period of time

前端 未结 9 1588
南方客
南方客 2020-12-06 01:53

Note: This question has been re-asked with a summary of all debugging attempts here.


I have a Python script that is running as a background pr

相关标签:
9条回答
  • 2020-12-06 02:49

    Virtual Memory matters!!!

    I encountered the same issue before I add swap to my OS. The formula for virtual memory is usually like: SwapSize + 50% * PhysicalMemorySize. I finally get this resolved by either adding more physical memory or adding a Swap disk. close_fds won't work in my case.

    0 讨论(0)
  • 2020-12-06 02:51

    You need to

    ps = subprocess.Popen(["sleep", "1000"])
    os.waitpid(ps.pid, 0)
    

    to free resources.

    Note: this does not work on Windows.

    0 讨论(0)
  • 2020-12-06 02:55

    That swap space answer is bogus. Historically Unix systems wanted swap space available like that, but they don't work that way anymore (and Linux never worked that way). You're not even close to running out of memory, so that's not likely the actual problem - you're running out of some other limited resource.

    Given where the error is occuring (_get_handles calls os.pipe() to create pipes to the child), the only real problem you could be running into is not enough free file descriptors. I would instead look for unclosed files (lsof -p on the PID of the process doing the popen). If your program really needs to keep a lot of files open at one time, then increase the user limit and/or the system limit for open file descriptors.

    0 讨论(0)
提交回复
热议问题