Boibot 发表于 2022-10-22 22:11:54

出现Python DeprecationWarning 类型错误,出现DeprecationWarning,需要替换最新的方法

import threading
import time


def timer():
    print()
    print()
    count = 0
    while True:
      time.sleep(1)
      count += 1
      print("logged in for", count, "seconds")


x = threading.Thread(target=timer, daemon=True)
x.setDaemon(True)
x.start()


print(x.isDaemon())

answer = input("Do you wish to exit?")

console window:
DeprecationWarning: setDaemon() is deprecated, set the daemon attribute instead
x.setDaemon(True)
DeprecationWarning: isDaemon() is deprecated, get the daemon attribute instead
print(x.isDaemon())

ba21 发表于 2022-10-22 22:29:27

提示已经告诉你用daemon 属性代替了
x.daemon = True
x.start()


print(x.daemon)
页: [1]
查看完整版本: 出现Python DeprecationWarning 类型错误,出现DeprecationWarning,需要替换最新的方法