KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > python > core > PyFinalizableInstance


1 // Copyright (c) Corporation for National Research Initiatives
2
// These are just like normal instances, except that their classes included
3
// a definition for __del__(), i.e. Python's finalizer. These two instance
4
// types have to be separated due to Java performance issues.
5

6 package org.python.core;
7
8
9 /**
10  * A python class instance with __del__ defined.
11  * <p>
12  * This is a special class due to performance. Defining
13  * finalize() on a class, makes the class a lot slower.
14  */

15
16 public class PyFinalizableInstance extends PyInstance
17 {
18     public PyFinalizableInstance(PyClass iclass) {
19         super(iclass);
20     }
21
22     // __del__ method is invoked upon object finalization.
23
protected void finalize() {
24         try {
25             instclass.__del__.__call__(this);
26         } catch (PyException exc) {
27             // Try to get the right method description.
28
PyObject method = instclass.__del__;
29             try {
30                 method = __findattr__("__del__");
31             } catch (PyException e) { ; }
32
33             Py.stderr.println("Exception " +
34                 Py.formatException(exc.type, exc.value, exc.traceback) +
35                 " in " + method +
36                 " ignored");
37         }
38     }
39 }
40
Popular Tags