py4j / py4j

Py4J enables Python programs to dynamically access arbitrary Java objects

Home Page:https://www.py4j.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question: how python handle new thread in callbacks?

zkycaesar opened this issue · comments

In my Python callback implementation, I start a new thead to run some task:

class PythonListener(object):

    def __init__(self, gateway):
        self.gateway = gateway

    def startPythonModule(self, func_param, common_param):
        log.info('start')

        def __run():
            # do some work

        threading.Thread(target=__run()).start()
        log.info('end')

    class Java:
        implements = ["com.xxx.PyProcInterface"]

When I call this method from Java, this call would not return until that thread finished. Why is that?

And if I don't want that call being blocked, what should I do? Some advice would be apprecaited.

Never mind, my mistake.

threading.Thread(target=__run()).start() -> threading.Thread(target=__run).start()