Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>On Unix-like system, a useful "external" way to monitor any process is the <a href="http://linux.die.net/man/1/ulimit" rel="nofollow noreferrer">ulimit</a> command (you don't clarify whether you want instead to run in Windows, where <code>ulimit</code> doesn't exist and other approaches may, but I don't know them;-).</p> <p>If you're thinking about performing such controls inside your own Python programs, just change the function in question to check the size of each object it's appending to the list (and keep a running total) and return when the running total reaches or exceeds a threshold (which you could pass as an extra parameter to the function in question).</p> <p><strong>Edit</strong>: the OP has clarified in a comment that they want the monitoring in the very worst place it could possibly be placed -- in the previous paragraphs, I mentioned how it's easy outside of the process, easy inside the function, but the OP wants it "smack in the middle";-). </p> <p>Least-bad way is probably with a "watchdog thread" -- a separate daemon thread in an infinite loop which, every <code>X</code> seconds, checks the process's resource consumption (e.g. with <a href="http://docs.python.org/library/resource.html?highlight=getrusag#resource.getrusage" rel="nofollow noreferrer">resource.getrusage</a>, if on Unix-like machines -- again, if on Windows, something else is needed instead) and, if that consumption exceeds the desired limits, attempts to kill the main thread with <a href="http://docs.python.org/library/thread.html?highlight=interrupt_main#thread.interrupt_main" rel="nofollow noreferrer">thread.interrupt_main</a>. Of course, this is fail from foolproof: the periodicity <code>X</code> (like in all cases of "polling") must be low enough to stop a runaway process in the meantime, but high enough to not slow the process down to a crawl. Plus, the main thread (the only one that can be interrupted like this) might be blocking exceptions (in which case the watchdog thread might perhaps try with "signals to this very process" of growing severity, all the way up to <code>SIGKILL</code>, the killer-signal that can never be blocked or intercepted).</p> <p>So, this intermediate approach is a lot more work than the <code>ulimit</code> command, is more fragile, and has no substantial added value. But, if you want to put the monitoring "inside the process but outside the resource-consuming function", with no advantages, lots of work, and the other disadvantages I've mentioned, this is the way to do it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload