Which again makes it clear how useless
__del__
is. For instance, if I where to use objects of a mutex guard class, I couldn't do the unlocking in the guard class's
__del__
method, because it's not enough to know that
__del__
will get called when ever the GC feels like doing its job ... I need to mutex released right when the guard object "goes out of scope" (I know that's stretching it, given Python's scoping rules). IMO
__del__
gives programmers the false impression that RAII in Python is doable via destructors when it really isn't. You have to use context managers for that. —
antred 23 secs ago