Skip to content

Hook into process of python object deallocation.

Notifications You must be signed in to change notification settings

WolframAlph/idk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

IDK

I dont know how to name this package.

Hook into process of python object deallocation.

import idk


def callback(obj_id):
    print(f"object {obj_id} was deallocated")


x = "delete me"
print(id(x))
idk.watch(x, callback)
del x

Dont confuse object deallocation and __del__ dunder method. __del__ is a finalizer and is called right before object is about to be deallocated. This however, does not guarantee that object was deallocated. Idk patches python in runtime to be able to hook into actual deallocation process and calls your callback right after deallocation routine of object is called. Callback receives 1 parameter which is id of just deallocated object. Important to note that it is still possible to have object alive after its deallocation routine was called in some scenarios under certain circumstances.

Important

This package is meant for education/debugging purposes. This is guaranteed to work only on linux/x86_64 and Python 3.9.0. Other configurations were not tested. Use it at your own risk.

About

Hook into process of python object deallocation.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published