python实现多线程

2021-06-04 00:04

阅读:367

标签:main   __name__   from   thread   import   star   targe   threading   函数   

from threading import Thread

# 方式一
# def sub_thread():
# 	for i in range(11):
# 		print(i)


# def main():
# 	t = Thread(target=sub_thread)
# 	t.start()
# 	for i in range(11):
# 		print(i)


# 方式二
class SubThread(Thread):

	def run(self):
		"""
		子线程任务函数
		"""
		for i in range(11):
			print(i)

def main():
	t = SubThread()
	t.start()
	for i in range(11):
		print(i)


if __name__ == "__main__":
	main()

python实现多线程

标签:main   __name__   from   thread   import   star   targe   threading   函数   

原文地址:https://www.cnblogs.com/gmbjzg/p/14667229.html


评论


亲,登录后才可以留言!