全国旗舰校区

不同学习城市 同样授课品质

北京

深圳

上海

广州

郑州

大连

武汉

成都

西安

杭州

青岛

重庆

长沙

哈尔滨

南京

太原

沈阳

合肥

贵阳

济南

下一个校区
就在你家门口
+
当前位置:首页  >  技术干货

python创建新线程有哪些方法

发布时间:2023-11-12 07:55:58
发布人:xqq

python创建新线程有哪些方法

1、方法

(1)直接创建threading.Thread对象,并把调用对象作为参数传入;

(2)继承threading.Thread类,重写run()方法。

2、实例

importthreading

importtime

defcatch_fish():

Pass

defone_thread():

start_time=time.time()

foriinrange(1,1001):

catch_fish()

end_time=time.time()

print("单线程测试耗时===%s"%str(end_time-start_time))

defmuti_thread():

start_time=time.time()

foriinrange(1,1001):

threading.Thread(target=catch_fish()).start()

end_time=time.time()

print("多线程测试耗时===%s"%str(end_time-start_time))

if__name__=='__main__':

#单线程

threading.Thread(one_thread()).start()

#多线程

muti_thread()

以上就是python创建新线程的方法,希望对大家有所帮助。更多Python学习教程请关注IT培训机构:千锋教育。

python培训

相关文章

python是什么意思啊

python是什么意思啊

2023-11-14
python库是什么意思

python库是什么意思

2023-11-14
python多进程取代多线程的探究

python多进程取代多线程的探究

2023-11-14
pythonGIL的原理

pythonGIL的原理

2023-11-14

最新文章

武汉新媒体行业公司排名

武汉新媒体行业公司排名

2023-11-01
武汉新媒体就业现状好吗

武汉新媒体就业现状好吗

2023-11-01
武汉全媒体行业发展现状及趋势

武汉全媒体行业发展现状及趋势

2023-10-31
武汉全媒体现状

武汉全媒体现状

2023-10-31
在线咨询 免费试学 教程领取