往期内容:
1、什么是多线程?
这一节主要学习Threading模块的一些基本操作,如获取线程数,添加线程等。
首先导入Threading模块
1 | import threading |
获取已激活的线程数
1 | threading.active_count() |
查看所有线程信息
1 | threading.enumerate() |
查看现在正在运行的线程
1 | threading.current_thread() |
添加线程,threading.Thread()接收参数target代表这个线程要完成的任务,需自行定义
1 | import threading |
运行结果:
1 | # python 2_add_thread.py |
代码项目地址:https://github.com/teamssix/Python-Threading-study-notes
参考文章:https://morvanzhou.github.io/tutorials/python-basic/threading