Prevent activating thread for second time


#1

Hi,

I’m able to run a thread, but how can I check if the thread is running to prevent activating it for the second time?

def boost_thread():
while 1 do something

......................

my_boost_thread = threading.Thread(boost_thread)

......................

        if my_boost_thread.is_alive() != True:
            my_boost_thread.start()

This doesn’t work?


#2

Hi @Marcel,

what I suggest you is to not create and delete threads repeatedly since these operations are quite intensive for a microcontroller board.

You could create your thread once and use synchronization primitives (Events, Locks, Semaphores) to control and resume its execution.

Let me know :slight_smile:


#3

Solved, in the thread I’m checking some “flags” to decide whether to pause or continue. Thanks.