Home > Net >  thread.is_alive() or thread.isAlive() not working
thread.is_alive() or thread.isAlive() not working

Time:09-17

I have the following thread

thread = threading.Thread(target=editing, args=(values['_CHECK_'], files, directory, window, progress_bar,), daemon=True).start()

and want to check whether the thread is still running or not.

if not thread.is_alive()
    pass

or

if not thread.isAlive():
    pass

are both not working. Why?

Exception:

File "Progress.py", line 101, in progress
    if not thread.isAlive():
AttributeError: 'NoneType' object has no attribute 'isAlive'

CodePudding user response:

This is because start() just Start the thread’s activity and return None. You probably indented to write

>>> thread = threading.Thread(target=editing, args=(values['_CHECK_'], files, directory, window, progress_bar,), daemon=True)
>>> thread.start() # start the thread
>>> is_alive = thread.is_alive()
>>> print(is_alive)
  • Related