python 线程模块

Python threading.main_thread()方法 (Python threading.main_thread() Method)

main_thread() is an inbuilt method of the threading module in Python. It is used to return the main Thread object. It is the thread from which the Python interpreter has started, in normal conditions.

main_thread()是Python中线程模块的内置方法。 它用于返回主线程对象。 在正常情况下,这是Python解释程序从其启动的线程。

Module:

模块:

    import threading

Syntax:

句法:

    main_thread()

Parameter(s):

参数:

  • None

    没有

Return value:

返回值:

The return type of this method is <class 'threading._MainThread'>, it returns the main Thread object.

此方法的返回类型为<class'threading._MainThread'> ,它返回主Thread对象。

Example:

例:

# Python program to explain the
# use of  main_thread()  method in Threading Module
import time
import threading
def thread_1(i):
time.sleep(5)
print("Value by Thread-:",i)
def thread_2(i):
print("Value by Thread-2:",i)
def thread_3(i):
time.sleep(4)
print("Value by Thread-3:",i)
def thread_4(i):
time.sleep(1)
print("Value by Thread-4:",i)
# Creating sample threads
thread1 = threading.Thread(target=thread_1, args=(10,))
thread2 = threading.Thread(target=thread_2, args=(20,))
thread3 = threading.Thread(target=thread_3, args=(30,))
thread4 = threading.Thread(target=thread_4, args=(50,))
print("Main thread for the given program:", threading.main_thread())
# Starting the threads
thread1.start()
thread2.start()
thread3.start()
thread4.start()

Output

输出量

Main thread for the given program: <_MainThread(MainThread, started 140269857195776)>
Value by Thread-2: 20
Value by Thread-4: 50
Value by Thread-3: 30
Value by Thread-: 10

翻译自: https://www.includehelp.com/python/threading-main_thread-method-with-example.aspx

python 线程模块

python 线程模块_Python线程模块| main_thread()方法与示例相关推荐

  1. python copy用法_Python 列表 copy() 使用方法及示例

    Python 列表 copy() 使用方法及示例 copy()方法返回列表的浅表副本. 列表可以被复制使用=运算符.例如:old_list = [1, 2, 3] new_list = old_lis ...

  2. python的构建工具setup.py的方法使用示例

    参考   python的构建工具setup.py的方法使用示例 - 云+社区 - 腾讯云 目录 一.构建工具setup.py的应用场景 二.setup.py介绍 三.setup.py的项目示例代码 四 ...

  3. python如何自定义模块_python自定义模块和开源模块使用方法

    模块,用一砣代码实现了某个功能的代码集合. 类似于函数式编程和面向过程编程,函数式编程则完成一个功能,其他代码用来调用即可,提供了代码的重用性和代码间的耦合.而对于一个复杂的功能来,可能需要多个函数才 ...

  4. python log模块_python日志模块logbook使用方法

    python自带了日志模块logging,可以用来记录程序运行过程中的日志信息.同时python还有logbook模块用来取代logging模块,在很多的项目中logbook模块使用也是比较的多,因此 ...

  5. python 判断线程状态_Python线程指南

    Python线程指南 本文介绍了Python对于线程的支持,包括"学会"多线程编程需要掌握的基础以及Python两个线程标准库的完整介绍及使用示例. 注意:本文基于Python2. ...

  6. python 线程池_Python线程池及其原理和使用(超级详细)

    系统启动一个新线程的成本是比较高的,因为它涉及与操作系统的交互.在这种情形下,使用线程池可以很好地提升性能,尤其是当程序中需要创建大量生存期很短暂的线程时,更应该考虑使用线程池. 线程池在系统启动时即 ...

  7. python多线程模块_python 多线程模块参考

    threading.active_count() 返回当前处于 active 状态的线程的数目 threading.current_thread() 返回调用者当前的 Thread 对象 thread ...

  8. python运行原理_Python线程池及其原理和使用(超级详细)

    系统启动一个新线程的成本是比较高的,因为它涉及与操作系统的交互.在这种情形下,使用线程池可以很好地提升性能,尤其是当程序中需要创建大量生存期很短暂的线程时,更应该考虑使用线程池. 线程池在系统启动时即 ...

  9. python线程状态_Python线程

    1. 线程基础 1.1. 线程状态 线程有5种状态,状态转换的过程如下图所示: 1.2. 线程同步(锁) 多线程的优势在于可以同时运行多个任务(至少感觉起来是这样).但是当线程需要共享数据时,可能存在 ...

最新文章

  1. 从马克思哲学客观原理角度——反思大学生创业2017-12-15
  2. 太原工业学院单片机课程设计_我系举办2014年单片机应用技能竞赛开幕式
  3. 123456789怎样运算等于1?答案可能很多,写个你最简单的方法
  4. 高效程序员的 7 项技能
  5. 互联网日报 | 7月4日 星期日 | 高途回应招聘团队被裁传闻;恒大半年劲销3568亿领跑行业;吉利发布共同富裕计划行动纲领...
  6. Linux 汇编学习
  7. 【优化调度】基于matlab蚁群算法求解无等待流水线调度优化问题【含Matlab源码 1516期】
  8. kubernetes多节点集群搭建过程分析
  9. 卫生事业单位计算机科学与技术,卫生事业单位考试(计算机科学与技术)知识点.doc...
  10. 用给定的key对字符串进行sha256加密-postman预处理
  11. mybatis的大于小于号转义符号
  12. 解决安装Ubuntu系统卡在载入界面,显示正在安装open vm tools
  13. applicationContext.xml 头信息
  14. 三、向SpringCloud注册Service服务(Restful服务)
  15. 问题解决:The connection to the server xxxxx:6443 was refused - did you specify the right host or port?
  16. spring cache ttl 过期
  17. 修改服务器2012r2核数,windows-server-2012-r2 – 如何从PS远程会话启动服务器核心上的Windows Update?...
  18. 穿越火线去除屏幕两边的矩形黑边
  19. A记录和CNAME记录——【网络】
  20. 无法超越的100米_百兆以太网传输距离_网线有哪几种?

热门文章

  1. java 审批流_一文读懂工作流
  2. timm 视觉库中的 create_model 函数详解
  3. jdbc连接数据scanip_JDBC连接数据库的四种方式:DriverManager,DataSource,DBCP,C3P0
  4. MySQL(7)索引
  5. 为什么计算机语言都是英语,编程为什么都是英语 编程为什么没有汉语
  6. conda失败说没有写权限_爱情中,为什么男生表白失败,女生还说可以继续做朋友,想过没有...
  7. Real提示“作为受限用户,您无足够的windows操作权限”的解决办法
  8. 谈谈我对MYSQL乱码的解决办法
  9. UVA272--TEX Quotes【字符串】
  10. Jetbrains 系 IDE 编辑器的代码提示功能