|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
写了一个最基本的多线程代码。。。可是打印出来确是下面这个样子的,十分不解,求大牛解答
- import threading
- import time
- # 为线程定义一个函数
- def target(threadName, delay):
- count = 0
- while count < 5:
- time.sleep(delay)
- count += 1
- print(threadName + time.ctime(time.time()))
- # 创建多个线程
- t1 = threading.Thread(target=target("First threads",1))
- t2 = threading.Thread(target=target("Second threads",1))
- t1.start()
- t1.join()
- t2.start()
- t2.join()
复制代码
First threadsWed Oct 18 18:17:51 2017
First threadsWed Oct 18 18:17:52 2017
First threadsWed Oct 18 18:17:54 2017
First threadsWed Oct 18 18:17:55 2017
First threadsWed Oct 18 18:17:56 2017
Second threadsWed Oct 18 18:17:57 2017
Second threadsWed Oct 18 18:17:58 2017
Second threadsWed Oct 18 18:17:59 2017
Second threadsWed Oct 18 18:18:00 2017
Second threadsWed Oct 18 18:18:01 2017
>>>
- t1 = threading.Thread(target=target, args=("First threads",1))
- t2 = threading.Thread(target=target, args=("Second threads",1))
- t1.start()
- t2.start()
- t1.join()
- t2.join()
复制代码
|
|