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]#
  • 相关阅读:
    顺序容器2(用法)
    运算符重载
    IO相关3(string流)
    IO相关2(文件输入输出)
    C语言--指针
    Java---匿名类
    Andriod开发 --插件安装、环境配置、问题集锦
    ubuntu--vim 技巧
    ubuntu--命令大全
    各浏览器userAgent汇总
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13348399.html
Copyright © 2011-2022 走看看