Memory monitoring under Python?

Torsten Luettgert shaitan at rosa.physik.TU-Berlin.DE
Tue Aug 29 06:22:05 EDT 2000


Hello,

I have a question:
is it possible in Python to effectively monitor the amount of memory (in
bytes) that a module takes? Or even better: trigger an exception if it
exceeds a given limit?


background:
I'm currently evaluating scripting languages for embedding user-supplied
scripts into a big, fat C++ application which must not die or hang.

The scripts cannot be individually verified, so I have to expect endless
loops, memory accumulation and perhaps even non-obvious attacks (DoS or
intrusion).

So far, Python is my favourite choice. RExec should prevent intrusion,
and the additional fine-tuning possibilities will come in handy, too.
Against hangs, a signal.alarm(some_limit) call and a (python) SIGALRM
handler which generates an exception will suffice - I just have to forbid
that someone uses 'except:'.

Memory will be more difficult to limit, I guess. I have some ideas
(creating multiple interpreters in threads, for example, or pickling every
script module's dictionary once in a while just to check the size of the
result), but I'm not too happy with them.

Thanks in advance for help,

Torsten (shaitan at physik.tu-berlin.de)

P.S.: please cc me, I don't always have the time to read the newsgroup,
and I could miss your reply by accident.


---------------------------------------------------------------------------
 Torsten Luettgert, shaitan at physik.tu-berlin.de
 To obtain public gpg key, send an empty mail with subject 'get public key'
 "I used to be an agnostic, but now I'm not so sure."
---------------------------------------------------------------------------



More information about the Python-list mailing list