For CPython, there is no good answer for this, which does not involve writing a Python C extension, since it mlockworks on pages, not objects. Even if you used ctypesto extract the necessary addresses and mlockused them through calls ctypes mlock, you will have some time determining when mlockand when munlock, you need to know the address and memory sizes of all protected data types; since it mlockworks on pages, you will need to carefully monitor how many objects are currently on any given page (because if you are simple mlockand munlockblind, and there are several things that need to be blocked on the page, the first munlockwill unlock all of them:mlock/munlock - a logical flag, it does not take into account the number of locks and unlocks).
, mlock, .
mmap memoryview (mmap , memoryview , ctypes mlock ), .
, Python , ; , (, ), , .