import _thread
from time import sleep, ctime
def thread1():
print('线程1开始:', ctime())
print('线程1挂起4秒')
sleep(4)
print('线程1结束:', ctime())
def thread2():
print('线程2开始:', ctime())
print('线程2挂起2秒')
sleep(2)
print('线程2结束:', ctime())
def thread3():
print('线程3开始:', ctime())
print('线程3挂起1秒')
sleep(1)
print('线程3结束', ctimr())
def main():
print('主线程开始!')
#线程函数为无参数函数,args为空元祖
_thread.start_new_thread(thread1, ())
_thread.start_new_thread(thread2,())
_thread.start_new_thread(thread3,())
sleep(6)
print('全部结束:', ctime())
if __name__ == '__main__':
main()
python#使用thread模块创建线程
最新推荐文章于 2023-02-09 09:39:31 发布