01: // Copyright (c) Corporation for National Research Initiatives
02: // These are just like normal instances, except that their classes included
03: // a definition for __del__(), i.e. Python's finalizer. These two instance
04: // types have to be separated due to Java performance issues.
05:
06: package org.python.core;
07:
08: /**
09: * A python class instance with __del__ defined.
10: * <p>
11: * This is a special class due to performance. Defining
12: * finalize() on a class, makes the class a lot slower.
13: */
14:
15: public class PyFinalizableInstance extends PyInstance {
16: public PyFinalizableInstance(PyClass iclass) {
17: super (iclass);
18: }
19:
20: // __del__ method is invoked upon object finalization.
21: protected void finalize() {
22: try {
23: instclass.__del__.__call__(this );
24: } catch (PyException exc) {
25: // Try to get the right method description.
26: PyObject method = instclass.__del__;
27: try {
28: method = __findattr__("__del__");
29: } catch (PyException e) {
30: ;
31: }
32:
33: Py.stderr.println("Exception "
34: + Py.formatException(exc.type, exc.value,
35: exc.traceback) + " in " + method
36: + " ignored");
37: }
38: }
39: }
|