python中的thread_Python中的thread

测试代码

import threading

import time

def do_thread_test():

print 'start thread time:', time.strftime('%H:%M:%S')

time.sleep(5)

print 'stop thread time:', time.strftime('%H:%M:%S')

threads = []

for i in range(2):

thread1 = threading.Thread(target=do_thread_test)

thread1.setDaemon(True)

threads.append(thread1)

for t in threads:

t.start()

for t in threads:

t.join()

print 'stop main thread', time.strftime('%H:%M:%S')

注释掉join,注释掉setDaemon(或设置为False),执行结果

start thread time: 21:57:40

start thread time: 21:57:40

stop main thread 21:57:40 主

stop thread time: 21:57:45

stop thread time: 21:57:45

注释掉join,设置setDaemon=True,执行结果

start thread time: 21:59:47

start thread time: 21:59:47

stop main thread 21:59:47

join方法的作用是阻塞,等待子线程结束

join无参数,注释掉setDaemon(或设置为True/False),执行结果

start thread time: 22:02:00

start thread time: 22:02:00

stop thread time: 22:02:05

stop thread time: 22:02:05

stop main thread 22:02:05 主

阻塞时间为time*thread_num

join参数为1,注释掉setDaemon(或设置为False),执行结果

start thread time: 22:11:22

start thread time: 22:11:22

stop main thread 22:11:24

stop thread time: 22:11:27

stop thread time: 22:11:27

join参数为1,设置setDaemon=True,执行结果(阻塞time*thread_num)

start thread time: 22:12:38

start thread time: 22:12:38

stop main thread 22:12:40

原文链接:https://blog.csdn.net/weixin_44961798/article/details/108269495

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/388951.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

--附加数据库失败

--附加数据库失败1.产生失败的原因比如有个数据库,名叫HIMS,它的数据文件HIMS_Data.mdf和日志文件HIMS_Log.ldf,都放在路径c:/Program Files/Microsoft SQL Server/MSSQL/data/下。但是这个数据库天天跑日志,会产生上G的日志,现在通过企业管理…

十三、原生爬虫实战

一、简单实例 1、需求:爬取熊猫直播某类主播人气排行 2、了解网站结构 分类——英雄联盟——"观看人数" 3、找到有用的信息 二、整理爬虫常规思路 1、使用工具chrome——F12——element——箭头——定位目标元素 目标元素:主播名字&#xff0c…

归一化 均值归一化_归一化折现累积收益

归一化 均值归一化Do you remember the awkward moment when someone you had a good conversation with forgets your name? In this day and age we have a new standard, an expectation. And when the expectation is not met the feeling is not far off being asked “w…

sqlserver垮库查询_Oracle和SQLServer中实现跨库查询

一、在SQLServer中连接另一个SQLServer库数据在SQL中,要想在本地库中查询另一个数据库中的数据表时,可以创建一个链接服务器:EXEC master.dbo.sp_addlinkedserver server N别名, srvproductN库名,providerNSQLOLEDB, datasrcN服务器地址EXEC…

Angular2+ typescript 项目里面用require

在typescript里面怎么使用require方法呢? const jQuery require(jquery); const fip require( fonticonpicker/fonticonpicker )( jQuery ); 如果什么都不做,直接在项目里面使用,会得到以下错误: Cannot find name require 以下…

机器学习实践三---神经网络学习

Neural Networks 在这个练习中,将实现神经网络BP算法,练习的内容是手写数字识别。Visualizing the data 这次数据还是5000个样本,每个样本是一张20*20的灰度图片fig, ax_array plt.subplots(nrows10, ncols10, figsize(6, 4))for row in range(10):fo…

Microsoft Expression Blend 2 密钥,key

Microsoft Expression Blend 2 密钥,key,序列TJ2R3-WHW22-B848T-B78YJ-HHJWJ号

ethereumjs/ethereumjs-common-3-test

查看test能够让你更好滴了解其API文档的使用 ethereumjs-common/tests/chains.js const tape require(tape) const Common require(../index.js)tape([Common]: Initialization / Chain params, function (t) {t.test(Should initialize with chain provided, function (st) …

mysql修改_mysql修改表操作

一: 修改表信息1.修改表名alter table test_a rename to sys_app;2.修改表注释alter table sys_application comment 系统信息表;二:修改字段信息1.修改字段类型和注释alter table sys_application modify column app_name varchar(20) COMMENT 应用的名…

机器学习实践四--正则化线性回归 和 偏差vs方差

这次实践的前半部分是,用水库水位的变化,来预测大坝的出水量。 给数据集拟合一条直线,可能得到一个逻辑回归拟合,但它并不能很好地拟合数据,这是高偏差(high bias)的情况,也称为“欠…

深度学习 推理 训练_使用关系推理的自我监督学习进行训练而无需标记数据

深度学习 推理 训练背景与挑战📋 (Background and challenges 📋) In a modern deep learning algorithm, the dependence on manual annotation of unlabeled data is one of the major limitations. To train a good model, usually, we have to prepa…

Android strings.xml中定义字符串显示空格

<string name"str">字 符 串</string> 其中 就表示空格。如果直接在里面键入空格&#xff0c;无论多少空格都只会显示一个。 用的XML转义字符记录如下&#xff1a; 空格&#xff1a; <string name"out_bound_submit">出 库</strin…

WCF开发入门的六个步骤

在这里我就用一个据于一个简单的场景&#xff1a;服务端为客服端提供获取客户信息的一个接口读取客户信息&#xff0c;来完成WCF开发入门的六个步骤。 1. 定义WCF服务契约 A. 项目引用节点右键添加引用。 B. 在代码文件里&#xff0c;添加以下命名空间的引…

LOJ116 有源汇有上下界最大流(上下界网络流)

考虑有源汇上下界可行流&#xff1a;由汇向源连inf边&#xff0c;那么变成无源汇图&#xff0c;按上题做法跑出可行流。此时该inf边的流量即为原图中该可行流的流量。因为可以假装把加上去的那些边的流量放回原图。 此时再从原来的源向原来的汇跑最大流。超源超汇相关的边已经流…

CentOS 7 使用 ACL 设置文件权限

Linux 系统标准的 ugo/rwx 集合并不允许为不同的用户配置不同的权限&#xff0c;所以 ACL 便被引入了进来&#xff0c;为的是为文件和目录定义更加详细的访问权限&#xff0c;而不仅仅是这些特别指定的特定权限。 ACL 可以为每个用户&#xff0c;每个组或不在文件所属组中的用…

机器学习实践五---支持向量机(SVM)

之前已经学到了很多监督学习算法&#xff0c; 今天的监督学习算法是支持向量机&#xff0c;与逻辑回归和神经网络算法相比&#xff0c;它在学习复杂的非线性方程时提供了一种更为清晰&#xff0c;更强大的方式。 Support Vector Machines SVM hypothesis Example Dataset 1…

作为微软技术.net 3.5的三大核心技术之一的WCF虽然没有WPF美丽的外观

作为微软技术.net 3.5的三大核心技术之一的WCF虽然没有WPF美丽的外观 但是它却是我们开发分布式程序的利器 但是目前关于WCF方面的资料相当稀少 希望我的这一系列文章可以帮助大家尽快入门 下面先介绍一下我的开发环境吧 操作系统&#xff1a;windows vista business版本 编译器…

服务器安装mysql_阿里云服务器上安装MySQL

关闭防火墙和selinuxCentOS7以下&#xff1a;service iptables stopsetenforce 0CentOS7.xsystemctl stop firewalldsystemctl disable firewalldsystemctl status firewalldvi /etc/selinux/config把SELINUXenforcing 改成 SELINUXdisabled一、安装依赖库yum -y install make …

在PyTorch中转换数据

In continuation of my previous post ,we will keep on deep diving into basic fundamentals of PyTorch. In this post we will discuss about ways to transform data in PyTorch.延续我以前的 发布后 &#xff0c;我们将继续深入研究PyTorch的基本原理。 在这篇文章中&a…

「网络流24题」试题库问题

传送门&#xff1a;>Here< 题意&#xff1a;有K种类型的共N道试题用来出卷子&#xff0c;要求卷子须有M道试题。已知每道题属于p种类型&#xff0c;每种类型的试题必须有且仅有k[i]道。现问出这套试卷的一种具体方案 思路分析 昨天打了一天的Dinic&#xff0c;今天又打了…