Python: How to NOT wait for a thread to finish to continue?

So, I have a code that waits for X to happen, then create a stream and process the Email.

What I'm looking for is a way for the code to continue to wait for X, although processEmail happens on a different thread, but currently the code is just waiting for the thread to finish before waiting for X to happen again.

if X happens:
    thread = Thread(target = processEmail.main())
    thread.start()

EDIT: FYI I have nothing that requires processEmail.main () to exit further down the code, so I don't have to wait for it to exit.

ANSWER Courtesy of Jean: Remove () after main.

+4
source share
1 answer

The problem is that you actually call your method when passing it as an argument Thread.

, , , , ( , , None, Thread, )

, , !

thread = Thread(target = processEmail.main)
thread.start()

. IDE, PyCharm, . :)

+6

Source: https://habr.com/ru/post/1666352/


All Articles