zoukankan      html  css  js  c++  java
  • python 线程间变量私有

    [root@yyjk ~/sbin/F5]#cat test4.py 
    import threading
    import time
    threads = []
    def fun9():
      x=100
      time.sleep(1)
      x= x+1;
      print x
      return x
      
      
    
    def fun10():
      x=200
      time.sleep(4)
      x=x+4
      print x
      return x;
    def fun11():
      x=300
      time.sleep(5)
      x=x+5
      print x;
      return x
      
    t9 = threading.Thread(target=fun9,name='fun9')
    threads.append(t9)
    t10 = threading.Thread(target=fun10,name='fun10')
    threads.append(t10)
    t11 = threading.Thread(target=fun11,name='fun11')
    threads.append(t11)
    
    for t in threads:
       t.setDaemon(True)
       t.start()
    for t in threads:
      t.join()
    
    [root@yyjk ~/sbin/F5]#vim test4.py
    [root@yyjk ~/sbin/F5]#cat test4.py 
    import threading
    import time
    threads = []
    def fun9():
      x=100
      time.sleep(1)
      x= x+1;
      print x
      return x
      
      
    
    def fun10():
      x=200
      time.sleep(7)
      x=x+4
      print x
      return x;
    def fun11():
      x=300
      time.sleep(5)
      x=x+5
      print x;
      return x
      
    t9 = threading.Thread(target=fun9,name='fun9')
    threads.append(t9)
    t10 = threading.Thread(target=fun10,name='fun10')
    threads.append(t10)
    t11 = threading.Thread(target=fun11,name='fun11')
    threads.append(t11)
    
    for t in threads:
       t.setDaemon(True)
       t.start()
    for t in threads:
      t.join()
    
    [root@yyjk ~/sbin/F5]#time python test4.py
    101
    305
    204
    
    real 0m7.051s
    user 0m0.014s
    sys 0m0.006s
    [root@yyjk ~/sbin/F5]#
  • 相关阅读:
    shiro注解,初始化资源和权限,会话管理
    shiro标签
    20个为前端开发者准备的文档和指南
    Canvas处理头像上传
    Chrome 实用调试技巧
    JS 代码编一个倒时器
    sql server优化
    在线图片压缩网站
    Request.QueryString
    C#网络爬虫
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13348399.html
Copyright © 2011-2022 走看看