#_author:来童星
#date:2019/12/17
#使用threading模块创建线程
import threading,time
def process():
for i in range(3):
time.sleep(1)
print('thread name is %s'%threading.current_thread().name)
if __name__=='__main__':
print('主线程开始')
threads=[threading.Thread(target=process) for i in range(4)]# 创建4个线程存入列表
for t in threads:
t.start()
for t in threads:
t.join()
print('主线程结束')
运行结果:
主线程开始
thread name is Thread-4
thread name is Thread-2
thread name is Thread-1
thread name is Thread-3
thread name is Thread-1
thread name is Thread-4
thread name is Thread-3
thread name is Thread-2
thread name is Thread-3
thread name is Thread-1
thread name is Thread-4
thread name is Thread-2
主线程结束

使用threading模块创建线程的更多相关文章

  1. Python使用Threading模块创建线程

    使用Threading模块创建线程,直接从threading.Thread继承,然后重写__init__方法和run方法: #!/usr/bin/python # -*- coding: UTF-8 ...

  2. threading模块创建线程

    什么是线程 (thread) 线程也是一种多任务编程方式,可以使用计算机的多核资源.线程被称为轻量级的进程. 线程特征 *线程计算机多核分配的最小单位 *一个进程可以包含多个线程 *线程也是一个运行的 ...

  3. python:threading多线程模块-创建线程

    创建线程的两种方法: 1,直接调用threading.Thread来构造thread对象,Thread的参数如下: class threading.Thread(group=None, target= ...

  4. Python——threading模块(线程)

    一.threading模块的对象 Thread:表示一个执行线程的对象 Lock:锁 Rlock:可重入锁对象 Condition:条件变量对象,使得一个线程等待另一个线程满足特定的“条件” Even ...

  5. 利用threading模块开线程

    一多线程的概念介绍 threading模块介绍 threading模块和multiprocessing模块在使用层面,有很大的相似性. 二.开启多线程的两种方式 1.创建线程的开销比创建进程的开销小, ...

  6. Python之网路编程利用threading模块开线程

    一多线程的概念介绍 threading模块介绍 threading模块和multiprocessing模块在使用层面,有很大的相似性. 二.开启多线程的两种方式 1 1.创建线程的开销比创建进程的开销 ...

  7. <python的线程与threading模块>

    <python的线程与threading模块> 一 线程的两种调用方式 threading 模块建立在thread 模块之上.thread模块以低级.原始的方式来处理和控制线程,而thre ...

  8. python——threading模块

    一.什么是线程 线程是操作系统能够进行运算调度的最小单位.进程被包含在进程中,是进程中实际处理单位.一条线程就是一堆指令集合. 一条线程是指进程中一个单一顺序的控制流,一个进程中可以并发多个线程,每条 ...

  9. Python学习笔记- Python threading模块

    Python threading模块 直接调用 # !/usr/bin/env python # -*- coding:utf-8 -*- import threading import time d ...

随机推荐

  1. JS对象 window对象 屏幕可用高和宽度 1. screen.availWidth 属性返回访问者屏幕的宽度,以像素计,减去界面特性,比如任务栏。 2. screen.availHeight 属

    屏幕可用高和宽度 1. screen.availWidth 属性返回访问者屏幕的宽度,以像素计,减去界面特性,比如任务栏. 2. screen.availHeight 属性返回访问者屏幕的高度,以像素 ...

  2. MHA + proxysql 高可用以及读写分离

    环境 vip 192.168.1.101 slave 192.168.1.16 5.7.17 3306 master 192.168.1.135 5.7.17 3306 proxysql 192.16 ...

  3. qdatatime大小

    QDateTime time1; QDateTime time2; uint stime = time1.toTime_t(); uint etime = time2.toTime_t(); int ...

  4. java多线程面试题选择题大全含答案

    v java多线程面试题选择题大全含答案 java多线程面试题选择题大全含答案 1.下面程序的运行结果()(选择一项)public static void main(String[] args) {T ...

  5. element 的时间快捷键

    1. <div> <el-date-picker v-model="value4" type="month" :picker-options= ...

  6. CentOS7.6 部署asp.net core2.2 应用

    1.安装.net Core SDK 在安装.NET之前,您需要注册Microsoft密钥,注册产品存储库并安装所需的依赖项.这只需要每台机器完成一次. 打开终端并运行以下命令: sudo rpm -U ...

  7. Codeforces F. Bits And Pieces(位运算)

    传送门. 位运算的比较基本的题. 考虑枚举\(i\),然后二进制位从大到小考虑, 对于第\(w\)位,如果\(a[i][w]=1\),那么对\(j.k\)并没有什么限制. 如果\(a[i][w]=0\ ...

  8. php-验证码类-PDO类-缩略图类

    Verify.class.php 验证码类 <?php class Verify{ const VERIFY_TYPE_NUM=1; const VERIFY_TYPE_EN=2; const ...

  9. RobotFramework 切换窗口控制的用法小结

    一:滚动条控制 应用场景:通过滚动条的上下,左右移动,才能让定位的元素可见.

  10. HIve分组查询返回每组的一条记录

    select a.lng,a.lat from (select row_number() over ( partition by uid,grid_id) as rnum,weighted_centr ...