__init__ is the initialiser

Chris Angelico rosuav at gmail.com
Mon Feb 3 02:37:17 CET 2014

On Mon, Feb 3, 2014 at 12:24 PM, Devin Jeanpierre
<jeanpierreda at gmail.com> wrote:
> On Sun, Feb 2, 2014 at 4:07 PM, Chris Angelico <rosuav at gmail.com> wrote:
>> On Mon, Feb 3, 2014 at 10:40 AM, Roy Smith <roy at panix.com> wrote:
>>> I'm reasonably sure you posted this as humor, but there is some truth in
>>> what you said.  In the crypto/security domain, you often want to keep a
>>> key or cleartext around only for the time it's needed, and scrub the
>>> memory it was occupying as soon as it is no longer in use.
>>> I don't know how you would do that in Python.
>> I did, but you're right.
>> It's fundamentally not possible in pure Python, because there's no way
>> to flag a block of memory as "do not page this to disk". For what
>> you're talking about to be at all possible, you would need support
>> from the language, from the OS,
> mlock on linux, VirtualAlloc (?) on windows. This can be done in
> CPython after the fact, but you'd want the memory to be unpageable
> before it has contents put in it, not after.

Yeah, like I said it needs language and OS support. There's no way to
call those APIs from pure Python code. (And I'm not sure whether those
functions work without appropriate CPU-level support; for instance,
what happens if your OS is running inside a VM?)

> Destroying memory is comparatively easy, as you say -- just make the
> object's internal state "invalid", rather than adding anything to the
> language.

Yeah. Works fine if you have a cooperative system that checks that
state every time; otherwise, it'd need at least some language support
(the goal is to have its destructor called and all its references
wiped, so resources get released).


More information about the Python-list mailing list