[Pyunit-interest] PyUnit with jython embeded into java + thread
Brought to you by:
purcell
From: Sebastien B. <Seb...@al...> - 2003-05-01 04:34:14
|
Hello ! - I'm embedding jython into a java process (succesful) to be able to startup a java srv (ORB initialization in a new thread and other socket openings). It runs fine (see EmlServerPy.java) when calling the main method in jython. - When I integrate with PyUnit, I launch the main of my program as first test with a dummy assert yet what I get is an infinite loop on this test. I don't know if it is linked to the fact that I spawn a new thread for the ORB startup in it or not but I'd fear so. thanx for any help. - I put some details on the implementaion == here is the EmlServerPy.java public static void main(String[] args) { EmlServerPy emlServerPy = new EmlServerPy(); basemain(args); } public int run() { final String METHOD = "EmlServerPy.run"; int status = 0; try { Log.trace (MODULE, "Running ORB... "); ORBManager.startORBThread(); // NONBLOCKING setupJython(); // create jythonInterp BLOCKING } catch (InitException ex) { Log.exception(MODULE,METHOD,"Exception during creation of server:",ex); status = 1; } return status; } protected void setupJython () throws InitException { Log.trace (MODULE, "Running Jython... "); System.setProperty("python.security.respectJavaAccessibility", "0"); PySystemState.initialize(System.getProperties(), System.getProperties(), new String[0]); // Create the interpreter. InteractiveConsole interp = new InteractiveConsole(); PyModule mod = imp.addModule("__main__"); interp.setLocals(mod.__dict__); String jythonFileName = Config.getProperty ("ems.jython"); if ((jythonFileName != null)&&(jythonFileName.length()!=0)) { try { Log.trace(MODULE,"Processing initial file "+jythonFileName+"."); interp.execfile(jythonFileName); } catch(Throwable oops) { Py.printException(oops); String msg = "Error processing "+jythonFileName+"."; Log.exception(MODULE, msg, oops); throw new InitException (msg); } Py.getSystemState().path.insert(0, new PyString("")); try { Log.trace(MODULE,"Running in interactive mode"); interp.interact(null); } catch(Throwable oops) { Py.printException(oops); String msg = "Error starting python interpretor"; Log.exception(MODULE, msg, oops); throw new InitException (msg); } } } == and here is my jython script: class SonetLinkTestCase(unittest.TestCase): def test1_serverStartup(self): print "TEST " # server startup args = ("-EMLid", serverId); EmlServerPy.main(args); self.assertEquals(1, 1) PyUnit loops on test1_serverStartup forever. == if I run the test offline it is working fine, I get back the hand and can launch other jython methods. thanx. seb. |