> 文档中心 > python多线程基础案例代码解析

python多线程基础案例代码解析


多线程基本案例

import threadingimport timedef hello():    while True: print("=== hello ... ...") time.sleep(0.2)#等待0.2秒def world():    while True: print("=== === world ... ...") time.sleep(0.3)#等待0.3秒if __name__ == '__main__':    # 创建线程对象    hello_thread = threading.Thread(target=hello)    world_thread = threading.Thread(target=world)    # 启动线程    hello_thread.start()    world_thread.start()    #手动停止,否则一直不停

运行结果:

python多线程基础案例代码解析

央视天气网