Search code examples
python-3.xpython-multithreadingconcurrent.futures

multiple concurrent threads with futures.threadpool


I am trying to run multiple threads alongside my main thread. Running one thread individually works fine with both threading.Thread and concurrent.futures.ThreadPoolExecutor. Running two separate threads does not work at all though. One of the threads just runs the entire time, locking up both other threads. There are no "shared" resources that get locked afaik,they have nothing to do with each other (except calling the next thread), so i don't understand why this won't work

My code looks like this:

with concurrent.futures.ThreadPoolExecutor() as executor:
            future = executor.submit(function())
            result = future.result()

And the function running inside the thread also calls :

function():
            with concurrent.futures.ThreadPoolExecutor() as executor:
            inner_result = (executor.submit(inner_function,"value")).result()

I've also tried running this function with: t = Thread(target=function..., getting the same result.

Is there something i am missing to running multiple concurrent threads in python?


Solution

  • The issue was passing a result instead of the function itself to the executor.

    this: executor.submit(function())

    should be: executor.submit(function)