[Python] python多线程模块thread使用范例 →→→→→进入此内容的聊天室

来自 , 2020-12-18, 写在 Python, 查看 108 次.
URL http://www.code666.cn/view/dafc8e8c
  1. #!/usr/bin/python
  2.  
  3. import thread
  4. import time
  5.  
  6. # Define a function for the thread
  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. # Create two threads as follows
  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: unable to start thread"
  20.  
  21. while 1:
  22.    pass
  23.  
  24.  
  25. #//python/8380

回复 "python多线程模块thread使用范例"

这儿你可以回复上面这条便签

captcha