shi123457_ 2022-04-01 20:52 采纳率: 66.7%
浏览 71
已结题

多线程运行多条测试用例怎么解决这个问题?

有一个简单的任务,每个任务都会睡眠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)

  • 写回答

1条回答 默认 最新

  • ash062 2022-04-01 21:13
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 4月16日
  • 已采纳回答 4月8日
  • 创建了问题 4月1日

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?