[Python] Kotlin/Java processBuilder efficiency vs python subprocesses

Discussão em 'Python' iniciado por Stack, Maio 18, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to create a program using JVM processes which needs to call a different language program with changing parameters each time, a lot of times.

    For example, let's say I need to call a node.js program via my main program (KotlinJvm) 1000 times in 10 seconds.

    Now, I'm using the ProcessBuilder class to create a new process so I can get the information back to my main function, but it's not fast enough. It's even slow :/

    I researched a bit and found out about the Python subprocess library. I tried to implement the same idea there. In Python 3.9 my implementation worked great! and fast.

    1. So I'm asking, what is the difference between Python subprocess and Jvm Process?

    2. Is there a way to create a JVM subprocess like Python?

    As I read, subprocesses can be created on the JVM too by calling .start() from the same ProcessBuilder, but it's still slow.

    Just to clarify, calling just once wouldn't have been a problem. The problem is that I need to call this file 1000 times in 10-20 seconds.

    Adding some code here for examples.

    Kotlin example - I tested a bit, and waitFor() function takes a long time, and that's my problem.

    val processBuilder = ProcessBuilder("node somefile.js")
    val process = processBuilder.start()
    process.waitFor()


    Python example

    import subprocess

    subprocess.Popen(["node", "somefile.js"])


    If these are the same, is there any way to optimize JVM process execution? Any environment changes?

    Continue reading...

Compartilhe esta Página