在之前使用python3,pycharm开发的情况下,设置守护线程的方式如下:
【子线程名】.setDaemon(True)。
在今天学习的过程中(python3.12环境),发现不能使用这个方法进行守护线程的设置了。报错如下:
DeprecationWarning: setDaemon() is deprecated, set the daemon attribute instead
f_dance.setDaemon(True)
意思是:setDaemon()方法被弃用,使用daemon属性代替这个方法。
于是print(help(threading))查看threading库文档:
setDaemon(self, daemonic) # | Set whether this thread is a daemon. # | # | This method is deprecated, use the .daemon property instead.
描述是一样的。于是现在正确的使用方法如下:
【子线程对象】.daemon = True