diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/BaseGfePyController.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/BaseGfePyController.java index 3305246d2d..e02600cd53 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/BaseGfePyController.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/BaseGfePyController.java @@ -51,6 +51,8 @@ import com.raytheon.viz.gfe.smartscript.FieldDefinition; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Nov 10, 2008 njensen Initial creation + * Jan 18, 2013 njensen Added garbageCollect() + * * * * @author njensen @@ -354,4 +356,20 @@ public abstract class BaseGfePyController extends PythonScript implements execute("addModule", INTERFACE, argMap); } + /** + * Runs the python garbage collector. This should be run at the end of a + * procedure or tool in case the custom python used tk. If the python used + * tk and it is not garbage collected, errors about invalid threads may + * occur when the garbage collector runs in another python interpreter. + */ + public void garbageCollect() { + try { + jep.eval("import gc"); + jep.eval("gc.collect()"); + } catch (JepException e) { + statusHandler.handle(Priority.PROBLEM, + "Error garbage collecting GFE python interpreter", e); + } + } + } diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/procedures/ProcedureJob.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/procedures/ProcedureJob.java index ab3d246e95..a9b8a5d7c3 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/procedures/ProcedureJob.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/procedures/ProcedureJob.java @@ -56,6 +56,7 @@ import com.raytheon.viz.gfe.jobs.AsyncProgressJob; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Oct 8, 2009 njensen Initial creation + * Jan 18, 2013 1509 njensen Garbage collect after running procedure * * * @@ -395,6 +396,7 @@ public class ProcedureJob extends AbstractQueueJob { statusHandler.handle(Priority.PROBLEM, "Error executing procedure " + procedureName, e); } finally { + controller.garbageCollect(); progressJob.done(pjStatus); } } diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/smarttool/script/SmartToolJob.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/smarttool/script/SmartToolJob.java index 05dcae6f9f..c154f9439b 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/smarttool/script/SmartToolJob.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/smarttool/script/SmartToolJob.java @@ -53,6 +53,7 @@ import com.raytheon.viz.gfe.smarttool.Tool; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Jan 19, 2010 njensen Initial creation + * Jan 18, 2013 1509 njensen Garbage collect after running tool * * * @@ -164,6 +165,7 @@ public class SmartToolJob extends AbstractQueueJob { "Error in smart tool", e); throw e; } finally { + python.garbageCollect(); progressJob.done(pjResult); req = request; request = null;