python 3 _thread 和 threading 最简单的使用

python 3 _thread 和 threading 最简单的使用

  • _thread

运行结束时,线程也会结束,所以想保持线程运行,输出worker内容,需要加上while 1: pass

import _thread
def worker():
    print("worker")
    # time.sleep( 1 )
    # return

_thread.start_new_thread(worker, ())

while 1:
   pass
  • threading
import threading
def worker():
    print("worker")
    # time.sleep( 1 )
    # return


threading.Thread(target = worker).start()

版权声明:本文为qq_41604498原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。