#python threading
import time
'''
每一秒中,输出:this is a demo!
'''
def serial():
'''串行输出'''
time.sleep(1)
print('this is a demo!')
def main():
for i in range(5):
serial()
if __name__ == '__main__':
main()
>>> this is a demo! this is a demo! this is a demo! this is a demo! this is a demo! >>>
#python threading
import threading
import time
'''
并行执行,输出:Good!Good!Good!Good!Good!
'''
def parallel():
'''并行输出'''
time.sleep(1)
print('Good!')
def main():
for i in range(5):
t = threading.Thread(target=parallel)
t.start()
if __name__ == '__main__':
main()
#python threading
import threading
import time
'''
并行执行,输出:
[<Thread(Thread-2, started 3480)>, <Thread(Thread-1, started 660)>,
<Thread(SockThread, started daemon 2920)>, <Thread(Thread-3, started 916)>,
<Thread(Thread-4, started 3476)>, <_MainThread(MainThread, started 3964)>,
<Thread(Thread-5, started 2060)>]
存在的线程数 : 7
Good!Good!Good!Good!Good!
'''
def parallel():
'''并行输出'''
time.sleep(1)
print('Good!')
def main():
for i in range(5):
t = threading.Thread(target=parallel)
t.start()
if __name__ == '__main__':
main()
print(threading.enumerate())
print('存在的线程数 : %d'%threading.active_count())
>>> [<Thread(SockThread, started daemon 15424)>, <Thread(Thread-3, started 15840)>, <Thread(Thread-1, started 10884)>, <Thread(Thread-2, started 14512)>, <Thread(Thread-4, started 13204)>, <_MainThread(MainThread, started 12924)>, <Thread(Thread-5, started 15476)>] 存在的线程数 : 7 >>> Good!Good!Good!Good!Good!
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有