From: <am...@us...> - 2009-10-06 12:27:59
|
Revision: 6840 http://jython.svn.sourceforge.net/jython/?rev=6840&view=rev Author: amak Date: 2009-10-06 12:27:51 +0000 (Tue, 06 Oct 2009) Log Message: ----------- Adding proper interpreter shutdown on servlet.destroy() for modjy. Fixes: http://bugs.jython.org/issue1474 Thanks to Colin Evans for reporting the issue. Modified Paths: -------------- trunk/jython/src/com/xhaus/modjy/ModjyJServlet.java trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestBase.java Added Paths: ----------- trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestServletLifecycle.java trunk/jython/tests/modjy/test_apps_dir/lifecycle_tests.py Modified: trunk/jython/src/com/xhaus/modjy/ModjyJServlet.java =================================================================== --- trunk/jython/src/com/xhaus/modjy/ModjyJServlet.java 2009-10-04 23:25:51 UTC (rev 6839) +++ trunk/jython/src/com/xhaus/modjy/ModjyJServlet.java 2009-10-06 12:27:51 UTC (rev 6840) @@ -127,6 +127,15 @@ } /** + * Close down the modjy servlet. + * + */ + @Override + public void destroy( ) { + interp.cleanup(); + } + + /** * Setup the modjy environment, i.e. 1. Find the location of the modjy.jar file and add it to * sys.path 2. Process the WEB-INF/lib-python directory, if it exists * Modified: trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestBase.java =================================================================== --- trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestBase.java 2009-10-04 23:25:51 UTC (rev 6839) +++ trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestBase.java 2009-10-06 12:27:51 UTC (rev 6840) @@ -194,7 +194,7 @@ super.setUp(); String jythonHome = System.getProperty("JYTHON_HOME"); setRealPath(jythonHome, jythonHome); - setRealPath("/WEB-INF/" + LIB_PYTHON_DIR, LIB_PYTHON_TEST_PATH); + setRealPath("/WEB-INF/" + LIB_PYTHON_DIR, LIB_PYTHON_TEST_PATH); setRealPath("/WEB-INF/lib/modjy.jar", "../modjy.jar"); setPythonHome(jythonHome); setAppDir(DEFAULT_APP_DIR); @@ -238,6 +238,7 @@ suite.addTestSuite(ModjyTestHeaders.class); suite.addTestSuite(ModjyTestContentHeaders.class); suite.addTestSuite(ModjyTestReturnIterable.class); + suite.addTestSuite(ModjyTestServletLifecycle.class); suite.addTestSuite(ModjyTestWebInf.class); suite.addTestSuite(ModjyTestWSGIStreams.class); suite.addTestSuite(PyServletTest.class); Added: trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestServletLifecycle.java =================================================================== --- trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestServletLifecycle.java (rev 0) +++ trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestServletLifecycle.java 2009-10-06 12:27:51 UTC (rev 6840) @@ -0,0 +1,42 @@ +/*### +# +# Copyright Alan Kennedy. +# +# You may contact the copyright holder at this uri: +# +# http://www.xhaus.com/contact/modjy +# +# The licence under which this code is released is the Apache License v2.0. +# +# The terms and conditions of this license are listed in a file contained +# in the distribution that also contained this file, under the name +# LICENSE.txt. +# +# You may also read a copy of the license at the following web address. +# +# http://modjy.xhaus.com/LICENSE.txt +# +###*/ + +package com.xhaus.modjy; + +import javax.servlet.http.HttpServlet; + +public class ModjyTestServletLifecycle extends ModjyTestBase { + + protected void lifecycleTestSetUp() throws Exception { + baseSetUp(); + setAppFile("lifecycle_tests.py"); + } + + public void testAtExitHandlersCalled() throws Exception { + System.setProperty("modjy", "here"); + lifecycleTestSetUp(); + createServlet(); + doGet(); + HttpServlet modjyServlet = getServlet(); + modjyServlet.destroy(); + assertEquals("gone", System.getProperty("modjy")); + } + +} Added: trunk/jython/tests/modjy/test_apps_dir/lifecycle_tests.py =================================================================== --- trunk/jython/tests/modjy/test_apps_dir/lifecycle_tests.py (rev 0) +++ trunk/jython/tests/modjy/test_apps_dir/lifecycle_tests.py 2009-10-06 12:27:51 UTC (rev 6840) @@ -0,0 +1,34 @@ +# -*- coding: windows-1252 -*- + +### +# +# Copyright Alan Kennedy. +# +# You may contact the copyright holder at this uri: +# +# http://www.xhaus.com/contact/modjy +# +# The licence under which this code is released is the Apache License v2.0. +# +# The terms and conditions of this license are listed in a file contained +# in the distribution that also contained this file, under the name +# LICENSE.txt. +# +# You may also read a copy of the license at the following web address. +# +# http://modjy.xhaus.com/LICENSE.txt +# +### + +import atexit + +def exit_func(): + import java + java.lang.System.setProperty("modjy", "gone") + +atexit.register(exit_func) + +def lifecycle_test(environ, start_response): + writer = start_response("200 OK", []) + writer("Hello World!") + return [] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |