赞
踩
- from threading import Thread
- import time
-
- def test():
- print("thread time:", time.time())
- time.sleep(3)
- for i in range(5):
- thread1 = Thread(target=test)
- thread1.start()
- from threading import Thread
- import time
-
- def test():
- print("thread time:", time.time())
- time.sleep(3)
- for i in range(5):
- thread1 = Thread(target=test())
- thread1.start()
这两段代码有什么区别吗,如果不小心看都注意不到,第一段代码是正确的实现方式,第二段代码target中的test函数加上了括号,实际上在thread1初始化时便开始执行了一次。
所以,切忌在target的函数加括号!!!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。