1 下列有一个简单的任务,每个任务都会睡眠10秒,如果是用单线程运行,至少要运行100秒,请使用多线程启动10个线程运行,实现10秒左右运行完所有任务
任务代码:
import unittest,threading
def test_task(name):
print(f"{threading.current_thread().name}:",name)
time.sleep(10)
class TestTask(unittest.TestCase):
def test01(self):
test_task(1)
def test02(self):
test_task(2)
def test03(self):
test_task(3)
def test04(self):
test_task(4)
def test05(self):
test_task(5)
def test06(self):
test_task(6)
def test07(self):
test_task(7)
def test08(self):
test_task(8)
def test09(self):
test_task(9)
def test10(self):
test_task(10)