测试

 1 #!/usr/bin/python3
 2 
 3 import _thread
 4 import time
 5 
 6 # 为线程定义一个函数
 7 def print_time( threadName, delay):
 8    count = 0
 9    while count < 5:
10       time.sleep(delay)
11       count += 1
12       print ("%s: %s" % ( threadName, time.ctime(time.time()) ))
13 
14 # 创建两个线程
15 try:
16    _thread.start_new_thread( print_time, ("Thread-1", 2, ) )
17    _thread.start_new_thread( print_time, ("Thread-2", 4, ) )
18 except:
19    print ("Error: 无法启动线程")
20 
21 while 1:
22    pass

写点东西测试一下

posted @ 2018-03-11 22:43  Gvenn  阅读(51)  评论(0)    收藏  举报