weixin_42691598 2021-03-10 16:24 采纳率: 33.3%
浏览 301
已结题

python threading.thread() 里while真时会一直循环,怎么解决?

import threading
from time import sleep
run = True
def test():
    while run:
        print("1")
        sleep(1)
thread = threading.Thread(target=test())
thread.start()
while True:
    print("2")
    sleep(1)

会一直输出1,但是我想1,2都输出,需要怎么解决?谢谢

  • 写回答

1条回答 默认 最新

  • 芫尘梦 2021-03-10 16:38
    关注

    改成 thread = threading.Thread(target=test)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 11月7日
  • 已采纳回答 10月30日