From: "Martin v. Löwis" <martin at v.loewis.de> > Consider this example, where X is a class that needs finally-ization, > and f and g are functions that participate in the protocol: > > def f(): > a = X() > g() > a.do_something() > > def g(): > b = X() > > Now, when f starts, an X instance is registered with the cleaner, > and this is assigned to the local variable a. Then g is invoked. > This creates another X instance that is also registered with the > cleaner. Then g returns, and all objects registered with the > cleaner are finally-ized. > At the moment, there are two objects > registered with the cleaner, so they are both finally-ized. Oh no, absolutely not! The objects are finaly-izated only for the frame where created. This is ensured because the cleaner uses a stack (unrelated to the frame stack), one item in the stack per function call. You will see this clearly if you look at the latest detscope.py. b is cleaned up upon return from g, and a will be cleaned up only upon return from f. Oliver
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4