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

 

相关文章:

  • 2021-11-12
  • 2021-12-31
  • 2021-10-24
  • 2021-12-04
  • 2021-08-04
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-27
  • 2022-02-07
  • 2021-07-23
  • 2021-12-18
  • 2022-01-12
  • 2021-10-20
相关资源
相似解决方案