1

I'm trying to write a python program that works with threads. I'm using concurrent.futures to handle the threads. In the programm one thread should create an PDF-File. Because this task is lasting very long I want to create a thread to handle the creation. But after sometime I want to work with the pdf file again. Therefore, I have to be sure, that the previous thread is finished.

My question is, how can I check if my concurrent future thread is finished or how I can wait on its execution.

Code

if __name__ == '__main__' with concurrent.futures.ThreadPoolExecutor() as executor: document = executor.submit(createPDF, pdfValues) #working on something different .... #Here I want to work with the pdf file again, via a new thread #Therefore I want to make sure that the thread above is finished. with concurrent.futures.ThreadPoolExecutor() as executor: result = executor.submit(workWithPDF, values) 

1 Answer 1

3

your document variable is of type concurrent.futures.Future, which has done() method that returns True if it completed, or result() that returns the result and blocks until it ready (if it still isn't)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.