方式一
from threading import Thread
import time
def hello(name):
time.sleep(2)
print(\'%s say hello\' %name)
if __name__ == \'__main__\':
t=Thread(target=hello,args=(\'xiaomao\',))
t.start()
print(\'主线程\')
方式二
from threading import Thread
import time
class Hello(Thread):
def __init__(self,name):
super().__init__()
self.name=name
def run(self):
time.sleep(2)
print(\'%s say hello\' % self.name)
if __name__ == \'__main__\':
t = Hello(\'xiaomao\')
t.start()
print(\'主线程\')
继续阅读与本文标签相同的文章
-
云上一指禅:大数据产品DataWorks每日问答
2026-05-18栏目: 教程
-
云数据库RDS是什么?
2026-05-18栏目: 教程
-
2019智能安防工程师大会在杭州成功召开
2026-05-18栏目: 教程
-
2018年中国专利申请154万件 超过日美 占全球近半
2026-05-18栏目: 教程
-
关于表变动而导致的实体变动问题
2026-05-18栏目: 教程
