[Python] python的threading和multiprocessing模块 →→→→→进入此内容的聊天室

来自 , 2021-04-30, 写在 Python, 查看 156 次.
URL http://www.code666.cn/view/d01c2557
  1.  
  2. #!/usr/bin/python  
  3. #-*-coding:utf-8-*-  
  4.  
  5. import threading  
  6. #用于线程执行的函数  
  7. def counter(n):  
  8.     cnt = 0;  
  9.     for i in xrange(n):  
  10.         for j in xrange(i):  
  11.             cnt += j;  
  12.     print cnt;              
  13.              
  14. if __name__ == '__main__':  
  15.     #初始化一个线程对象,传入函数counter,及其参数1000  
  16.     th = threading.Thread(target=counter, args=(1000,));  
  17.     #启动线程  
  18.     th.start();  
  19.     #主线程阻塞等待子线程结束  
  20.     th.join();  
  21.  
  22.  
  23. #//python/5616

回复 "python的threading和multiprocessing模块"

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

captcha