开发者

When java program is started using Python's subprocess.Popen() exits, why database connection opened by the subprocess is not closed?

开发者 https://www.devze.com 2023-01-11 23:31 出处:网络
We use Robot Framework for test automation, and our jy开发者_StackOverflow中文版thon test code spawns a java subprocess using subprocess.Popen():

We use Robot Framework for test automation, and our jy开发者_StackOverflow中文版thon test code spawns a java subprocess using subprocess.Popen():

    cmd = "java -jar program.jar"
    process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
    process.wait()

Java code utilizes a JDBC connection to Oracle database, and the same program needs to be executed several times successively.

Our issue is, that after the java program exits the database connection to Oracle is not closed - and after several executions the tests start to fail because Oracle won't accept more connections.

netstat shows, that the stale TCP connections to Oracle are owned by jython's PID (=parent process).

Why aren't the connections closed when the java program (=subprocess) exits?


I'm not sure but it's possible that because you're using Jython, the interpreter is given ownership of the connections (and hence they survive until that process dies). Have you tried using process.terminate() after the process.wait()?


Consider using os.kill (which is used by process.terminate in >= 2.6).

If that doesn't work, given your unusual setup - JVMs invoking JVMs, not usually necessary - you may want to use something like execnet (http://codespeak.net/execnet/) to start a CPython process to control this. CPython has more functionality for accessing host operating system services than what we have provided in Jython. Using execnet is a good way to combine these strengths together.

0

精彩评论

暂无评论...
验证码 换一张
取 消