zoukankan      html  css  js  c++  java
  • python 多线程

    1. 进程

      python /tmp/2.py > /tmp/log&

    pid  进程唯一标识符  kill pidNum

    创建一个进程的时候,会创建一个主线程

    一个进程中只有一个主线程

    主线程可以生成多个子线程,主线程和子线程一起就可以称之为多线程

    全局锁:  在任意指定的时间里,有且只有一个线程在运行

     1 import time
     2 import threading
     3 
     4 
     5 def test(p):
     6     time.sleep(0.001)
     7     print(p)
     8 
     9 
    10 def test2():
    11     print('1')
    12 
    13 
    14 ts = []
    15 
    16 for i in range(0,100):
    17     th = threading.Thread(target=test,args=[i])
    18     ts.append(th)
    19 
    20 for i in ts:
    21     i.start()
    22 
    23 for i in ts:
    24     i.join()
    25 
    26 print('hello, end !!'

    join 的意思就是会等待所有的子线程都执行完成之后再继续执行(print('hello, end !!)语句)

  • 相关阅读:
    zfs
    targetcli
    targetcli
    自动制linux iso包
    yum解决重复包,依赖冲突问题
    lvm相关
    vmware相关
    配置本地yum源
    k8s安装prometheus监控
    流水线基础-Pipeline
  • 原文地址:https://www.cnblogs.com/liyugeng/p/7906620.html
Copyright © 2011-2022 走看看