When running the file Chapter05/example6.py in Python 3.9 or newer, this error is raised:
AttributeError: 'MyThread' object has no attribute 'isAlive'. Did you mean: 'is_alive'?
This can be fixed by renaming the method at line 21.
alive = [1 if thread.isAlive() else 0 for thread in threads] # original
alive = [1 if thread.is_alive() else 0 for thread in threads] # solution
Also when running the script under Python 3.10 or newer, a warning is emitted:
DeprecationWarning: setDaemon() is deprecated, set the daemon attribute instead
The issue can be fixed by changing the line 41 like so:
thread.setDaemon(True) # original
thread.daemon = True # solution
The method threading.currentThread was also deprecated in favor of threading.current_thread. When running scripts Chapter12/example3.py and Chapter12/example4.py a warning will be emitted:
DeprecationWarning: currentThread() is deprecated, use current_thread() instead
Interestingly, in chapter 13, the correct method threading.current_thread is used.
When running the file Chapter05/example6.py in Python 3.9 or newer, this error is raised:
This can be fixed by renaming the method at line 21.
Also when running the script under Python 3.10 or newer, a warning is emitted:
The issue can be fixed by changing the line 41 like so:
The method
threading.currentThread
was also deprecated in favor ofthreading.current_thread
. When running scripts Chapter12/example3.py and Chapter12/example4.py a warning will be emitted:Interestingly, in chapter 13, the correct method
threading.current_thread
is used.