当前vscode环境下 多进程多线程运行情况探究

我的代码

其中在“打开图片时”、“进入子进程之前”、“子进程join前”、“进入子进程区域后”,“子进程join后”、“进入子线程区域后”分别打印了进程线程的编号和数量。

# -*- coding: utf-8 -*-# Form implementation generated from reading ui file 'test2.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.
'''
这个文件用于显示PyQt,无需输入正确的账号和密码就可以登录进去
选择图片的时候只能选择28*28像素的图片,也就是TestDigitImgs的第一张图片
'''
'''PyQt'''
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QFileDialog
from PyQt5.QtCore import QUrl
from PyQt5.QtGui import QDesktopServices
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap
from PyQt5.QtCore import QThread, pyqtSignal
from PyQt5.QtWidgets import  QApplication, QFileDialog, QMessageBox
from PyQt5.Qt import Qt, QIcon
from PyQt5 import QtCore, QtGui, QtWidgets
'''调用类'''
import os
from multiprocessing import Process
from multiprocessing import Process, Queue
import threading
# from Docx import GenerateDocx
# import cv2
# import math
# import utils
# import numpy as np
# from docx2pdf import convert# from mmdeploy_runtime import Detector, Classifier
# from datetime import datetime
# 获取当前日期和时间INFER_WINDOW_SIZE = [1024, 1024]
INFER_WINDOW_STRIDES = (960, 960)
OVERLAP_NMS_THRESHOLD = 0.5
BBOX_DISPLAY_CONFIDENCE = 0.5CATEGORY_COLOR = {   'papule':(140,240,255),'nevus':(162,247,223),'nodule':(152,192,250),'open_comedo':(86,143,128),'closed_comedo':(60,57,166),'atrophic_scar':(103,49,132),'hypertrophic_scar':(249,233,160),'melasma':(164,93,222),'pustule':(235,177,161),'other':(233,222,252)}CATEGORY_INDEX = {0:'papule',1:'nevus',2:'nodule',3:'open_comedo',4:'closed_comedo',5:'atrophic_scar',6:'hypertrophic_scar',7:'melasma',8:'pustule',9:'other'}CLASSIFICATION_DRUG = {1:"无需治疗",2:"BPO或弱效维A酸类外用",3:"BPO联合维A酸类外用",4:"BPO联合维A酸,考虑口服抗生素",5:"BPO联合维A酸,口服抗生素",6:"BPO联合维A酸,口服抗生素,并开始考虑异维A酸",7:"BPO联合维A酸,口服抗生素,推荐异维A酸",8:"异维A酸"
}QApplication.processEvents()class Ui_MainWindow(object):def setupUi(self, MainWindow):MainWindow.setObjectName("MainWindow")MainWindow.resize(1410, 902)MainWindow.setWindowIcon(QIcon('./icon/main.ico'))self.centralwidget = QtWidgets.QWidget(MainWindow)self.centralwidget.setObjectName("centralwidget")self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)self.verticalLayout.setObjectName("verticalLayout")self.groupBox_main = QtWidgets.QGroupBox(self.centralwidget)self.groupBox_main.setTitle("")self.groupBox_main.setObjectName("groupBox_main")self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.groupBox_main)self.verticalLayout_2.setObjectName("verticalLayout_2")self.horizontalLayout_largest = QtWidgets.QHBoxLayout()self.horizontalLayout_largest.setObjectName("horizontalLayout_largest")self.groupBox_left = QtWidgets.QGroupBox(self.groupBox_main)self.groupBox_left.setMinimumSize(QtCore.QSize(320, 0))self.groupBox_left.setMaximumSize(QtCore.QSize(320, 16777215))self.groupBox_left.setTitle("")self.groupBox_left.setObjectName("groupBox_left")self.verticalLayout_8 = QtWidgets.QVBoxLayout(self.groupBox_left)self.verticalLayout_8.setObjectName("verticalLayout_8")self.groupBox_menu = QtWidgets.QGroupBox(self.groupBox_left)self.groupBox_menu.setMinimumSize(QtCore.QSize(300, 40))self.groupBox_menu.setMaximumSize(QtCore.QSize(16777215, 40))self.groupBox_menu.setTitle("")self.groupBox_menu.setObjectName("groupBox_menu")self.horizontalLayout_6 = QtWidgets.QHBoxLayout(self.groupBox_menu)self.horizontalLayout_6.setObjectName("horizontalLayout_6")self.label_menu = QtWidgets.QLabel(self.groupBox_menu)self.label_menu.setStyleSheet("font-size: 22px;")self.label_menu.setObjectName("label_menu")self.horizontalLayout_6.addWidget(self.label_menu)spacerItem = QtWidgets.QSpacerItem(205, 17, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)self.horizontalLayout_6.addItem(spacerItem)self.verticalLayout_8.addWidget(self.groupBox_menu)self.groupBox_startAction = QtWidgets.QGroupBox(self.groupBox_left)self.groupBox_startAction.setMaximumSize(QtCore.QSize(16777215, 130))self.groupBox_startAction.setTitle("")self.groupBox_startAction.setObjectName("groupBox_startAction")self.verticalLayout_4 = QtWidgets.QVBoxLayout(self.groupBox_startAction)self.verticalLayout_4.setObjectName("verticalLayout_4")self.horizontalLayout_imgAndDir = QtWidgets.QHBoxLayout()self.horizontalLayout_imgAndDir.setObjectName("horizontalLayout_imgAndDir")self.pushButton_selectImg = QtWidgets.QPushButton(self.groupBox_startAction)self.pushButton_selectImg.setMinimumSize(QtCore.QSize(20, 40))self.pushButton_selectImg.setStyleSheet("font-size: 18px;")self.pushButton_selectImg.setObjectName("pushButton_selectImg")self.horizontalLayout_imgAndDir.addWidget(self.pushButton_selectImg)self.pushButton_selectDir = QtWidgets.QPushButton(self.groupBox_startAction)self.pushButton_selectDir.setMinimumSize(QtCore.QSize(0, 40))self.pushButton_selectDir.setStyleSheet("font-size: 18px;")self.pushButton_selectDir.setObjectName("pushButton_selectDir")self.horizontalLayout_imgAndDir.addWidget(self.pushButton_selectDir)self.verticalLayout_4.addLayout(self.horizontalLayout_imgAndDir)self.pushButton_startAction = QtWidgets.QPushButton(self.groupBox_startAction)self.pushButton_startAction.setMinimumSize(QtCore.QSize(50, 40))self.pushButton_startAction.setStyleSheet("font-size: 18px;")self.pushButton_startAction.setObjectName("pushButton_startAction")self.verticalLayout_4.addWidget(self.pushButton_startAction)self.verticalLayout_8.addWidget(self.groupBox_startAction)self.groupBox = QtWidgets.QGroupBox(self.groupBox_left)self.groupBox.setMinimumSize(QtCore.QSize(0, 62))self.groupBox.setTitle("")self.groupBox.setObjectName("groupBox")self.horizontalLayout_3 = QtWidgets.QHBoxLayout(self.groupBox)self.horizontalLayout_3.setObjectName("horizontalLayout_3")self.horizontalLayout = QtWidgets.QHBoxLayout()self.horizontalLayout.setObjectName("horizontalLayout")self.pushButton_save = QtWidgets.QPushButton(self.groupBox)self.pushButton_save.setMinimumSize(QtCore.QSize(0, 40))self.pushButton_save.setStyleSheet("font-size: 18px;")self.pushButton_save.setObjectName("pushButton_save")self.horizontalLayout.addWidget(self.pushButton_save)self.lineEdit_savePath = QtWidgets.QLineEdit(self.groupBox)self.lineEdit_savePath.setMinimumSize(QtCore.QSize(0, 40))self.lineEdit_savePath.setObjectName("lineEdit_savePath")self.horizontalLayout.addWidget(self.lineEdit_savePath)self.horizontalLayout_3.addLayout(self.horizontalLayout)self.verticalLayout_8.addWidget(self.groupBox)self.groupBox_showDir = QtWidgets.QGroupBox(self.groupBox_left)self.groupBox_showDir.setMinimumSize(QtCore.QSize(0, 50))self.groupBox_showDir.setMaximumSize(QtCore.QSize(16777215, 55))self.groupBox_showDir.setTitle("")self.groupBox_showDir.setObjectName("groupBox_showDir")self.horizontalLayout_10 = QtWidgets.QHBoxLayout(self.groupBox_showDir)self.horizontalLayout_10.setObjectName("horizontalLayout_10")self.pushButton_showPDF = QtWidgets.QPushButton(self.groupBox_showDir)self.pushButton_showPDF.setMinimumSize(QtCore.QSize(0, 40))self.pushButton_showPDF.setStyleSheet("font-size: 18px;")self.pushButton_showPDF.setObjectName("pushButton_showPDF")self.horizontalLayout_10.addWidget(self.pushButton_showPDF)self.verticalLayout_8.addWidget(self.groupBox_showDir)self.verticalLayout_result = QtWidgets.QVBoxLayout()self.verticalLayout_result.setObjectName("verticalLayout_result")self.groupBox_resultTitle = QtWidgets.QGroupBox(self.groupBox_left)self.groupBox_resultTitle.setMinimumSize(QtCore.QSize(0, 50))self.groupBox_resultTitle.setMaximumSize(QtCore.QSize(16777215, 50))self.groupBox_resultTitle.setTitle("")self.groupBox_resultTitle.setObjectName("groupBox_resultTitle")self.horizontalLayout_8 = QtWidgets.QHBoxLayout(self.groupBox_resultTitle)self.horizontalLayout_8.setObjectName("horizontalLayout_8")self.label_resultTitle = QtWidgets.QLabel(self.groupBox_resultTitle)self.label_resultTitle.setStyleSheet("font-size: 22px;")self.label_resultTitle.setObjectName("label_resultTitle")self.horizontalLayout_8.addWidget(self.label_resultTitle)spacerItem1 = QtWidgets.QSpacerItem(181, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)self.horizontalLayout_8.addItem(spacerItem1)self.verticalLayout_result.addWidget(self.groupBox_resultTitle)self.groupBox_resultContent = QtWidgets.QGroupBox(self.groupBox_left)self.groupBox_resultContent.setMinimumSize(QtCore.QSize(0, 50))self.groupBox_resultContent.setTitle("")self.groupBox_resultContent.setObjectName("groupBox_resultContent")self.horizontalLayout_9 = QtWidgets.QHBoxLayout(self.groupBox_resultContent)self.horizontalLayout_9.setObjectName("horizontalLayout_9")self.listWidget = QtWidgets.QListWidget(self.groupBox_resultContent)self.listWidget.setLayoutDirection(QtCore.Qt.LeftToRight)self.listWidget.setStyleSheet("font-size: 14px;")self.listWidget.setIconSize(QtCore.QSize(7, 7))self.listWidget.setObjectName("listWidget")item = QtWidgets.QListWidgetItem()self.listWidget.addItem(item)item = QtWidgets.QListWidgetItem()self.listWidget.addItem(item)item = QtWidgets.QListWidgetItem()self.listWidget.addItem(item)item = QtWidgets.QListWidgetItem()self.listWidget.addItem(item)item = QtWidgets.QListWidgetItem()icon = QtGui.QIcon()icon.addPixmap(QtGui.QPixmap("./icon/closed_comedo.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)item.setIcon(icon)self.listWidget.addItem(item)item = QtWidgets.QListWidgetItem()icon1 = QtGui.QIcon()icon1.addPixmap(QtGui.QPixmap("./icon/opend_comedo.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)item.setIcon(icon1)self.listWidget.addItem(item)item = QtWidgets.QListWidgetItem()icon2 = QtGui.QIcon()icon2.addPixmap(QtGui.QPixmap("./icon/papule.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)item.setIcon(icon2)self.listWidget.addItem(item)item = QtWidgets.QListWidgetItem()icon3 = QtGui.QIcon()icon3.addPixmap(QtGui.QPixmap("./icon/pustule.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)item.setIcon(icon3)self.listWidget.addItem(item)item = QtWidgets.QListWidgetItem()icon4 = QtGui.QIcon()icon4.addPixmap(QtGui.QPixmap("./icon/nodule.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)item.setIcon(icon4)self.listWidget.addItem(item)item = QtWidgets.QListWidgetItem()icon5 = QtGui.QIcon()icon5.addPixmap(QtGui.QPixmap("./icon/atrophic_scar.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)item.setIcon(icon5)self.listWidget.addItem(item)item = QtWidgets.QListWidgetItem()icon6 = QtGui.QIcon()icon6.addPixmap(QtGui.QPixmap("./icon/hypertrophic_scar.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)item.setIcon(icon6)self.listWidget.addItem(item)item = QtWidgets.QListWidgetItem()icon7 = QtGui.QIcon()icon7.addPixmap(QtGui.QPixmap("./icon/melasma.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)item.setIcon(icon7)self.listWidget.addItem(item)item = QtWidgets.QListWidgetItem()icon8 = QtGui.QIcon()icon8.addPixmap(QtGui.QPixmap("./icon/nevus.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)item.setIcon(icon8)self.listWidget.addItem(item)item = QtWidgets.QListWidgetItem()icon9 = QtGui.QIcon()icon9.addPixmap(QtGui.QPixmap("./icon/other.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)item.setIcon(icon9)self.listWidget.addItem(item)self.horizontalLayout_9.addWidget(self.listWidget)self.verticalLayout_result.addWidget(self.groupBox_resultContent)self.verticalLayout_8.addLayout(self.verticalLayout_result)self.verticalLayout_advice = QtWidgets.QVBoxLayout()self.verticalLayout_advice.setObjectName("verticalLayout_advice")self.groupBox_10 = QtWidgets.QGroupBox(self.groupBox_left)self.groupBox_10.setMinimumSize(QtCore.QSize(0, 50))self.groupBox_10.setMaximumSize(QtCore.QSize(16777215, 50))self.groupBox_10.setTitle("")self.groupBox_10.setObjectName("groupBox_10")self.horizontalLayout_12 = QtWidgets.QHBoxLayout(self.groupBox_10)self.horizontalLayout_12.setObjectName("horizontalLayout_12")self.label_adviceTitle = QtWidgets.QLabel(self.groupBox_10)self.label_adviceTitle.setMinimumSize(QtCore.QSize(0, 30))self.label_adviceTitle.setStyleSheet("font-size: 22px;")self.label_adviceTitle.setObjectName("label_adviceTitle")self.horizontalLayout_12.addWidget(self.label_adviceTitle)spacerItem2 = QtWidgets.QSpacerItem(137, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)self.horizontalLayout_12.addItem(spacerItem2)self.verticalLayout_advice.addWidget(self.groupBox_10)self.groupBox_12 = QtWidgets.QGroupBox(self.groupBox_left)self.groupBox_12.setMinimumSize(QtCore.QSize(0, 70))self.groupBox_12.setMaximumSize(QtCore.QSize(16777215, 120))self.groupBox_12.setTitle("")self.groupBox_12.setObjectName("groupBox_12")self.horizontalLayout_13 = QtWidgets.QHBoxLayout(self.groupBox_12)self.horizontalLayout_13.setObjectName("horizontalLayout_13")self.label_adviceResult = QtWidgets.QLabel(self.groupBox_12)self.label_adviceResult.setMinimumSize(QtCore.QSize(0, 50))self.label_adviceResult.setMaximumSize(QtCore.QSize(16777215, 120))self.label_adviceResult.setStyleSheet("font-size: 16px;")self.label_adviceResult.setAlignment(QtCore.Qt.AlignCenter)self.label_adviceResult.setObjectName("label_adviceResult")self.horizontalLayout_13.addWidget(self.label_adviceResult)self.verticalLayout_advice.addWidget(self.groupBox_12)self.verticalLayout_8.addLayout(self.verticalLayout_advice)self.horizontalLayout_largest.addWidget(self.groupBox_left)self.groupBox_right = QtWidgets.QGroupBox(self.groupBox_main)self.groupBox_right.setTitle("")self.groupBox_right.setObjectName("groupBox_right")self.verticalLayout_3 = QtWidgets.QVBoxLayout(self.groupBox_right)self.verticalLayout_3.setObjectName("verticalLayout_3")self.groupBox_selectImg = QtWidgets.QGroupBox(self.groupBox_right)self.groupBox_selectImg.setMinimumSize(QtCore.QSize(0, 40))self.groupBox_selectImg.setMaximumSize(QtCore.QSize(16777215, 40))self.groupBox_selectImg.setTitle("")self.groupBox_selectImg.setObjectName("groupBox_selectImg")self.horizontalLayout_5 = QtWidgets.QHBoxLayout(self.groupBox_selectImg)self.horizontalLayout_5.setObjectName("horizontalLayout_5")self.label_imgTitle = QtWidgets.QLabel(self.groupBox_selectImg)self.label_imgTitle.setMinimumSize(QtCore.QSize(0, 20))self.label_imgTitle.setStyleSheet("font-size: 20px;")self.label_imgTitle.setObjectName("label_imgTitle")self.horizontalLayout_5.addWidget(self.label_imgTitle)self.lineEdit_imgPath = QtWidgets.QLineEdit(self.groupBox_selectImg)self.lineEdit_imgPath.setMinimumSize(QtCore.QSize(0, 25))self.lineEdit_imgPath.setMaximumSize(QtCore.QSize(300, 16777215))self.lineEdit_imgPath.setObjectName("lineEdit_imgPath")self.horizontalLayout_5.addWidget(self.lineEdit_imgPath)spacerItem3 = QtWidgets.QSpacerItem(287, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)self.horizontalLayout_5.addItem(spacerItem3)self.label_5 = QtWidgets.QLabel(self.groupBox_selectImg)self.label_5.setText("")self.label_5.setObjectName("label_5")self.horizontalLayout_5.addWidget(self.label_5)self.verticalLayout_3.addWidget(self.groupBox_selectImg)self.horizontalLayout_imgs = QtWidgets.QHBoxLayout()self.horizontalLayout_imgs.setObjectName("horizontalLayout_imgs")self.label_showImg = QtWidgets.QLabel(self.groupBox_right)self.label_showImg.setMinimumSize(QtCore.QSize(500, 0))self.label_showImg.setText("")self.label_showImg.setAlignment(QtCore.Qt.AlignCenter)self.label_showImg.setObjectName("label_showImg")self.horizontalLayout_imgs.addWidget(self.label_showImg)spacerItem4 = QtWidgets.QSpacerItem(10, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)self.horizontalLayout_imgs.addItem(spacerItem4)self.label_showImg2 = QtWidgets.QLabel(self.groupBox_right)self.label_showImg2.setMinimumSize(QtCore.QSize(500, 0))self.label_showImg2.setText("")self.label_showImg2.setAlignment(QtCore.Qt.AlignCenter)self.label_showImg2.setObjectName("label_showImg2")self.horizontalLayout_imgs.addWidget(self.label_showImg2)self.verticalLayout_3.addLayout(self.horizontalLayout_imgs)self.horizontalLayout_pageTurning = QtWidgets.QHBoxLayout()self.horizontalLayout_pageTurning.setObjectName("horizontalLayout_pageTurning")self.prev_image_button = QtWidgets.QPushButton(self.groupBox_right)self.prev_image_button.setMinimumSize(QtCore.QSize(0, 30))self.prev_image_button.setObjectName("prev_image_button")self.horizontalLayout_pageTurning.addWidget(self.prev_image_button)self.label_pageNum = QtWidgets.QLabel(self.groupBox_right)self.label_pageNum.setMinimumSize(QtCore.QSize(80, 0))self.label_pageNum.setMaximumSize(QtCore.QSize(50, 16777215))self.label_pageNum.setAlignment(QtCore.Qt.AlignCenter)self.label_pageNum.setObjectName("label_pageNum")self.horizontalLayout_pageTurning.addWidget(self.label_pageNum)self.next_image_button = QtWidgets.QPushButton(self.groupBox_right)self.next_image_button.setMinimumSize(QtCore.QSize(0, 30))self.next_image_button.setObjectName("next_image_button")self.horizontalLayout_pageTurning.addWidget(self.next_image_button)self.verticalLayout_3.addLayout(self.horizontalLayout_pageTurning)self.horizontalLayout_largest.addWidget(self.groupBox_right)self.verticalLayout_2.addLayout(self.horizontalLayout_largest)self.groupBox_botton = QtWidgets.QGroupBox(self.groupBox_main)self.groupBox_botton.setMinimumSize(QtCore.QSize(0, 32))self.groupBox_botton.setTitle("")self.groupBox_botton.setObjectName("groupBox_botton")self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.groupBox_botton)self.horizontalLayout_2.setObjectName("horizontalLayout_2")self.label_condition = QtWidgets.QLabel(self.groupBox_botton)self.label_condition.setMinimumSize(QtCore.QSize(0, 12))self.label_condition.setObjectName("label_condition")self.horizontalLayout_2.addWidget(self.label_condition)self.verticalLayout_2.addWidget(self.groupBox_botton)self.verticalLayout.addWidget(self.groupBox_main)MainWindow.setCentralWidget(self.centralwidget)self.retranslateUi(MainWindow)QtCore.QMetaObject.connectSlotsByName(MainWindow)def retranslateUi(self, MainWindow):_translate = QtCore.QCoreApplication.translateMainWindow.setWindowTitle(_translate("MainWindow", "痤疮检测"))self.label_menu.setText(_translate("MainWindow", "菜单栏"))self.pushButton_selectImg.setText(_translate("MainWindow", "选择图片"))self.pushButton_selectDir.setText(_translate("MainWindow", "选择文件夹"))self.pushButton_startAction.setText(_translate("MainWindow", "开始检测"))self.pushButton_save.setText(_translate("MainWindow", "保存报告"))self.pushButton_showPDF.setText(_translate("MainWindow", "显示输出文件夹"))self.label_resultTitle.setText(_translate("MainWindow", "检测结果"))__sortingEnabled = self.listWidget.isSortingEnabled()self.listWidget.setSortingEnabled(False)item = self.listWidget.item(0)item.setText(_translate("MainWindow", "痤疮分级结果:待检测"))item = self.listWidget.item(2)item.setText(_translate("MainWindow", "各类别痤疮检测数量:"))item = self.listWidget.item(4)item.setText(_translate("MainWindow", "  闭口粉刺:待检测"))item = self.listWidget.item(5)item.setText(_translate("MainWindow", "  开口粉刺:待检测"))item = self.listWidget.item(6)item.setText(_translate("MainWindow", "  丘疹:待检测"))item = self.listWidget.item(7)item.setText(_translate("MainWindow", "  脓疱:待检测"))item = self.listWidget.item(8)item.setText(_translate("MainWindow", "  结节:待检测"))item = self.listWidget.item(9)item.setText(_translate("MainWindow", "  萎缩性瘢痕:待检测"))item = self.listWidget.item(10)item.setText(_translate("MainWindow", "  增生性瘢痕刺:待检测"))item = self.listWidget.item(11)item.setText(_translate("MainWindow", "  斑:待检测"))item = self.listWidget.item(12)item.setText(_translate("MainWindow", "  色素痣:待检测"))item = self.listWidget.item(13)item.setText(_translate("MainWindow", "  其他:待检测"))self.listWidget.setSortingEnabled(__sortingEnabled)self.label_adviceTitle.setText(_translate("MainWindow", "推荐治疗方案"))self.label_adviceResult.setText(_translate("MainWindow", "用药指南"))self.label_imgTitle.setText(_translate("MainWindow", "所选图片"))self.prev_image_button.setText(_translate("MainWindow", "上一页"))self.label_pageNum.setText(_translate("MainWindow", "共 0 页"))self.next_image_button.setText(_translate("MainWindow", "下一页"))self.label_condition.setText(_translate("MainWindow", "系统运行情况"))# 按钮关联函数self.pushButton_selectDir.clicked.connect(self.openImageFolder)# self.pushButton_startAction.clicked.connect(self.startAction)self.pushButton_selectImg.clicked.connect(self.openImage)self.pushButton_startAction.clicked.connect(self.start_work)# self.worker_thread.finished.connect(self.on_worker_finished)self.pushButton_save.clicked.connect(self.start_work_pdf)# self.worker_thread_pdf.finished.connect(self.on_worker_finished_pdf)self.pushButton_showPDF.clicked.connect(self.button_show_dir)self.prev_image_button.clicked.connect(self.showPrevImage)self.next_image_button.clicked.connect(self.showNextImage)QApplication.processEvents()def start_work(self):def run_child_process():QApplication.processEvents()self.pushButton_startAction.setEnabled(False)  # 禁用按钮self.pushButton_selectImg.setEnabled(False)  # 禁用按钮self.pushButton_save.setEnabled(False)  # 禁用按钮self.pushButton_showPDF.setEnabled(False)  # 禁用按钮self.pushButton_selectDir.setEnabled(False)  # 禁用按钮self.prev_image_button.setEnabled(False)self.next_image_button.setEnabled(False)self.label_condition.setText('正在检测,请耐心等待')import multiprocessingprint("主线程join前:")process_info = multiprocessing.current_process()print(f"当前进程数量: {multiprocessing.cpu_count()}")print(f"当前进程编号: {process_info.name}")# 打印当前线程数量和编号thread_info = threading.current_thread()print(f"当前线程数量: {threading.active_count()}")print(f"当前线程编号: {thread_info.name}")print("启动进程")p = Worker(self.q, self.selected_imgPaths,self.now)p.daemon = Truep.start()p.join()import multiprocessingprint("主线程join后:")process_info = multiprocessing.current_process()print(f"当前进程数量: {multiprocessing.cpu_count()}")print(f"当前进程编号: {process_info.name}")# 打印当前线程数量和编号thread_info = threading.current_thread()print(f"当前线程数量: {threading.active_count()}")print(f"当前线程编号: {thread_info.name}")self.generated_image_paths = self.q.get()self.generated_docxFilePath_List = self.q.get()self.text = self.q.get()print("我得到啦")self.label_condition.setText('检测完毕,请点击保存图片')self.pushButton_startAction.setEnabled(True)  # 启动之前被禁用的按钮self.pushButton_selectImg.setEnabled(True)self.pushButton_save.setEnabled(True)  self.pushButton_showPDF.setEnabled(True)  self.pushButton_selectDir.setEnabled(True)self.prev_image_button.setEnabled(True)self.next_image_button.setEnabled(True)img_path = self.selected_imgPaths[0]img_name = os.path.splitext(os.path.basename(img_path))[0]grading_result = self.text[img_name]["grading_result"]item = self.listWidget.item(0)item.setText(f"痤疮分级结果:{grading_result}") item = self.listWidget.item(2)item.setText("各类别痤疮检测数量:")item = self.listWidget.item(4)closed_comedo_count = self.text[img_name]["category_count"]["closed_comedo"]item.setText(f"  闭口粉刺:{closed_comedo_count}")item = self.listWidget.item(5)open_comedo_count = self.text[img_name]["category_count"]["open_comedo"]item.setText(f"  开口粉刺:{open_comedo_count}")item = self.listWidget.item(6)papule_count = self.text[img_name]["category_count"]["papule"]item.setText(f"  丘疹:{papule_count}")item = self.listWidget.item(7)pustule_count = self.text[img_name]["category_count"]["pustule"]item.setText(f"  脓疱:{pustule_count}")item = self.listWidget.item(8)nodule_count = self.text[img_name]["category_count"]["nodule"]item.setText(f"  结节:{nodule_count}")item = self.listWidget.item(9)atrophic_scar_count = self.text[img_name]["category_count"]["atrophic_scar"]item.setText(f"  萎缩性瘢痕:{atrophic_scar_count}")item = self.listWidget.item(10)hypertrophic_scar_count = self.text[img_name]["category_count"]["hypertrophic_scar"]item.setText(f"  增生性瘢痕刺:{hypertrophic_scar_count}")item = self.listWidget.item(11)melasma_count = self.text[img_name]["category_count"]["melasma"]item.setText(f"  斑:{melasma_count}")item = self.listWidget.item(12)nevus_count = self.text[img_name]["category_count"]["nevus"]item.setText(f"  色素痣:{nevus_count}")item = self.listWidget.item(13)other_count = self.text[img_name]["category_count"]["other"]item.setText(f"  其他:{other_count}")img_path = self.generated_image_paths[0]# 通过文件路径获取图片文件,并设置图片长宽为label控件的长、宽img = QtGui.QPixmap(img_path).scaled(self.label_showImg2.width(), self.label_showImg2.height(), Qt.KeepAspectRatio,Qt.SmoothTransformation)# 在label控件上显示选择的图片self.label_showImg2.setPixmap(img)#显示用药指南self.label_adviceResult.setText(CLASSIFICATION_DRUG[grading_result])# if self.thread.is_alive():#     self.thread.join()  # 等待子线程完成self.thread = threading.Thread(target=run_child_process)self.thread.setDaemon(True)self.thread.start()# self.thread.join()# print("ok")def start_work_pdf(self):import multiprocessingprint("进入子线程区域后:")process_info = multiprocessing.current_process()print(f"当前进程数量: {multiprocessing.cpu_count()}")print(f"当前进程编号: {process_info.name}")# 打印当前线程数量和编号thread_info = threading.current_thread()print(f"当前线程数量: {threading.active_count()}")print(f"当前线程编号: {thread_info.name}")if len(self.generated_image_paths) == 0:returnself.dir_choose = QFileDialog.getExistingDirectory(self.centralwidget, "选取文件夹", "./report_pdf")if self.dir_choose == '':print("未生成报告,保存无效")self.label_condition.setText('未生成报告,保存无效')returnelse:# f=open(fd,'w')import queuefor i in range(len(self.generated_image_paths)):QApplication.processEvents()img_name = os.path.splitext(os.path.basename(self.generated_docxFilePath_List[i]))[0]self.label_condition.setText(f"正在生成{img_name}.pdf报告")# 创建队列对象data_queue = queue.Queue()data_queue.put(self.generated_docxFilePath_List[i])data_queue.put(self.dir_choose)# 启动工作线程self.worker_pdf = threading.Thread(target=self.my_thread_pdf,args=(data_queue,))self.worker_pdf.setDaemon(True)self.worker_pdf.start()def my_thread_pdf(self,data_queue_in):from docx2pdf import convert# 执行耗时的任务generated_docxFilePath = data_queue_in.get()dir_choose = data_queue_in.get()img_name = os.path.splitext(os.path.basename(generated_docxFilePath))[0]convert(generated_docxFilePath, dir_choose+f"/{img_name}.pdf")print("pdf报告全部转换完毕")self.label_condition.setText(f"pdf报告生成完毕")self.lineEdit_savePath.setText(self.dir_choose)self.label_condition.setText('已保存所有报告')def showNextImage(self):if len(self.selected_imgPaths) == 0:returnself.current_image_index += 1if self.current_image_index >= len(self.selected_imgPaths):self.current_image_index = 0img_path = self.selected_imgPaths[self.current_image_index]img = QtGui.QPixmap(img_path).scaled(self.label_showImg.width(), self.label_showImg.height(), Qt.KeepAspectRatio,Qt.SmoothTransformation)self.label_showImg.setPixmap(img)self.lineEdit_imgPath.setText(img_path)pageNum = len(self.selected_imgPaths)current_image_index_fact = self.current_image_index + 1self.label_pageNum.setText(f"{current_image_index_fact} / {pageNum} ")if len(self.text) == len(self.selected_imgPaths):img_name = os.path.splitext(os.path.basename(img_path))[0]# self.label_showResult.setText(self.text[img_name])# print(self.text[img_name])grading_result = self.text[img_name]["grading_result"]self.label_adviceResult.setText(CLASSIFICATION_DRUG[grading_result])item = self.listWidget.item(0)item.setText(f"痤疮分级结果:{grading_result}")item = self.listWidget.item(2)item.setText("各类别痤疮检测数量:")item = self.listWidget.item(4)closed_comedo_count = self.text[img_name]["category_count"]["closed_comedo"]item.setText(f"  闭口粉刺:{closed_comedo_count}")item = self.listWidget.item(5)open_comedo_count = self.text[img_name]["category_count"]["open_comedo"]item.setText(f"  开口粉刺:{open_comedo_count}")item = self.listWidget.item(6)papule_count = self.text[img_name]["category_count"]["papule"]item.setText(f"  丘疹:{papule_count}")item = self.listWidget.item(7)pustule_count = self.text[img_name]["category_count"]["pustule"]item.setText(f"  脓疱:{pustule_count}")item = self.listWidget.item(8)nodule_count = self.text[img_name]["category_count"]["nodule"]item.setText(f"  结节:{nodule_count}")item = self.listWidget.item(9)atrophic_scar_count = self.text[img_name]["category_count"]["atrophic_scar"]item.setText(f"  萎缩性瘢痕:{atrophic_scar_count}")item = self.listWidget.item(10)hypertrophic_scar_count = self.text[img_name]["category_count"]["hypertrophic_scar"]item.setText(f"  增生性瘢痕刺:{hypertrophic_scar_count}")item = self.listWidget.item(11)melasma_count = self.text[img_name]["category_count"]["melasma"]item.setText(f"  斑:{melasma_count}")item = self.listWidget.item(12)nevus_count = self.text[img_name]["category_count"]["nevus"]item.setText(f"  色素痣:{nevus_count}")item = self.listWidget.item(13)other_count = self.text[img_name]["category_count"]["other"]item.setText(f"  其他:{other_count}")img_path2 = self.generated_image_paths[self.current_image_index]img2 = QtGui.QPixmap(img_path2).scaled(self.label_showImg2.width(), self.label_showImg2.height(), Qt.KeepAspectRatio,Qt.SmoothTransformation)self.label_showImg2.setPixmap(img2)def showPrevImage(self):if len(self.selected_imgPaths) == 0:returnself.current_image_index -= 1if self.current_image_index < 0:self.current_image_index = len(self.selected_imgPaths) - 1img_path = self.selected_imgPaths[self.current_image_index]img = QtGui.QPixmap(img_path).scaled(self.label_showImg.width(), self.label_showImg.height(), Qt.KeepAspectRatio,Qt.SmoothTransformation)self.label_showImg.setPixmap(img)self.lineEdit_imgPath.setText(img_path)pageNum = len(self.selected_imgPaths)current_image_index_fact = self.current_image_index + 1self.label_pageNum.setText(f"{current_image_index_fact} / {pageNum} ")img_path = self.selected_imgPaths[self.current_image_index]img_name = os.path.splitext(os.path.basename(img_path))[0]grading_result = self.text[img_name]["grading_result"]if len(self.text) == len(self.selected_imgPaths):img_name = os.path.splitext(os.path.basename(img_path))[0]# self.label_showResult.setText(self.text[img_name])# print(self.text[img_name])grading_result = self.text[img_name]["grading_result"]self.label_adviceResult.setText(CLASSIFICATION_DRUG[grading_result])item = self.listWidget.item(0)item.setText(f"痤疮分级结果:{grading_result}")item = self.listWidget.item(2)item.setText("各类别痤疮检测数量:")item = self.listWidget.item(4)closed_comedo_count = self.text[img_name]["category_count"]["closed_comedo"]item.setText(f"  闭口粉刺:{closed_comedo_count}")item = self.listWidget.item(5)open_comedo_count = self.text[img_name]["category_count"]["open_comedo"]item.setText(f"  开口粉刺:{open_comedo_count}")item = self.listWidget.item(6)papule_count = self.text[img_name]["category_count"]["papule"]item.setText(f"  丘疹:{papule_count}")item = self.listWidget.item(7)pustule_count = self.text[img_name]["category_count"]["pustule"]item.setText(f"  脓疱:{pustule_count}")item = self.listWidget.item(8)nodule_count = self.text[img_name]["category_count"]["nodule"]item.setText(f"  结节:{nodule_count}")item = self.listWidget.item(9)atrophic_scar_count = self.text[img_name]["category_count"]["atrophic_scar"]item.setText(f"  萎缩性瘢痕:{atrophic_scar_count}")item = self.listWidget.item(10)hypertrophic_scar_count = self.text[img_name]["category_count"]["hypertrophic_scar"]item.setText(f"  增生性瘢痕刺:{hypertrophic_scar_count}")item = self.listWidget.item(11)melasma_count = self.text[img_name]["category_count"]["melasma"]item.setText(f"  斑:{melasma_count}")item = self.listWidget.item(12)nevus_count = self.text[img_name]["category_count"]["nevus"]item.setText(f"  色素痣:{nevus_count}")item = self.listWidget.item(13)other_count = self.text[img_name]["category_count"]["other"]item.setText(f"  其他:{other_count}")img_path2 = self.generated_image_paths[self.current_image_index]img2 = QtGui.QPixmap(img_path2).scaled(self.label_showImg2.width(), self.label_showImg2.height(), Qt.KeepAspectRatio,Qt.SmoothTransformation)self.label_showImg2.setPixmap(img2)def button_show_dir(self):default_dir = "./report_pdf"show_dirPath = 0if self.dir_choose == '':show_dirPath = default_direlse:show_dirPath = self.dir_chooseurl = QUrl.fromLocalFile(show_dirPath)if url:print("选择的文件夹路径:", show_dirPath)else:print("未选择文件夹")QDesktopServices.openUrl(url)# 选择本地图片上传def openImage(self):import multiprocessingprint("打开图片时:")process_info = multiprocessing.current_process()print(f"当前进程数量: {multiprocessing.cpu_count()}")print(f"当前进程编号: {process_info.name}")# 打印当前线程数量和编号thread_info = threading.current_thread()print(f"当前线程数量: {threading.active_count()}")print(f"当前线程编号: {thread_info.name}")self.selected_imgPaths = [] # 清空之前选择的所有图片self.generated_image_paths = [] # 清空之前推理生成的所有图片empty_pixmap = QPixmap()self.label_showImg.setPixmap(empty_pixmap)self.label_showImg2.setPixmap(empty_pixmap)# 弹出一个文件选择框,第一个返回值imgName记录选中的文件路径+文件名,第二个返回值imgType记录文件的类型# QFileDialog就是系统对话框的那个类第一个参数是上下文,第二个参数是弹框的名字,第三个参数是默认打开的路径,第四个参数是需要的格式self.selected_imgPaths, _ = QtWidgets.QFileDialog.getOpenFileNames(self, "打开图片", "./pending_images", "*.jpg;;*.JPG;;*.png;;*.png;;All Files(*)")if len(self.selected_imgPaths) == 0:print('没有选择图片!')self.label_condition.setText("没有选择图片!") # 点击选择图片按钮后不选择图片会将存放图片路径的列表置为空# 创建一个空的QPixmap对象empty_pixmap = QPixmap()self.label_showImg.setPixmap(empty_pixmap)pageNum = 0self.label_pageNum.setText(f"共 {pageNum} 页")return# 通过文件路径获取图片文件,并设置图片长宽为label控件的长、宽img = QtGui.QPixmap(self.selected_imgPaths[0]).scaled(self.label_showImg.width(), self.label_showImg.height(), Qt.KeepAspectRatio,Qt.SmoothTransformation)# 提示点击生成self.label_condition.setText("请点击 开始检测")# 在label控件上显示选择的图片self.label_showImg.setPixmap(img)# 显示所选图片的路径self.lineEdit_imgPath.setText(self.selected_imgPaths[0])pageNum = len(self.selected_imgPaths)self.label_pageNum.setText(f"共 {pageNum} 页")# 选择图片文件夹上传def openImageFolder(self):self.selected_imgPaths = [] # 清空之前选择的所有图片self.generated_image_paths = [] # 清空之前推理生成的所有图片empty_pixmap = QPixmap()self.label_showImg.setPixmap(empty_pixmap)self.label_showImg2.setPixmap(empty_pixmap)# 弹出一个文件夹选择框,返回选中的文件夹路径selected_folder = QtWidgets.QFileDialog.getExistingDirectory(self, "选择文件夹", "./pending_images")if selected_folder:# 获取文件夹中的所有图片文件路径for file_name in os.listdir(selected_folder):if file_name.lower().endswith((".jpg", ".png")):self.selected_imgPaths.append(os.path.join(selected_folder, file_name))# 通过第一个图片文件路径获取图片,并设置图片长宽为label控件的长、宽img = QtGui.QPixmap(self.selected_imgPaths[0]).scaled(self.label_showImg.width(), self.label_showImg.height(), Qt.KeepAspectRatio,Qt.SmoothTransformation)# 提示点击开始检测self.label_condition.setText("请点击 开始检测")# 在label控件上显示第一张图片self.label_showImg.setPixmap(img)# 显示所选图片的路径self.lineEdit_imgPath.setText(self.selected_imgPaths[0])pageNum = len(self.selected_imgPaths)self.label_pageNum.setText(f"共 {pageNum} 页")else:print('没有选择图片!')self.label_condition.setText("没有选择图片!")empty_pixmap = QPixmap()self.label_showImg.setPixmap(empty_pixmap)pageNum = 0self.label_pageNum.setText(f"共 {pageNum} 页")returndef closeEvent(self, event):# 在这里执行你的函数self.delete_files_in_current_folder()if self.thread.is_alive():self.thread.join()  # 等待子线程完成# self.p.terminate()event.accept()# 删除中途产生的图片和docx文件def delete_files_in_current_folder(self):# 获取当前文件夹路径# current_folder = os.path.dirname(self.generated_docxFilePath)current_folder = "./result"# 获取当前文件夹中的所有文件if len(current_folder) == 0:print('没有报告生成')returnfile_list = os.listdir(current_folder)# 遍历文件列表for file_name in file_list:# 构建文件的绝对路径file_path = os.path.join(current_folder, file_name)# 判断是否是文件if os.path.isfile(file_path):# 删除文件os.remove(file_path)# 自定义的工作线程类
class Worker(Process):# 生成对应预测的数字# 定义一个信号,用于在工作完成后发送通知# on_result = pyqtSignal(object,object,object)QApplication.processEvents()def __init__(self, q, selected_imgPaths,now):super().__init__()self.q = qself.selected_imgPaths = selected_imgPathsself.generated_image_paths = []self.text = {}self.generated_docxFilePath_List = []self.now = now# self.detector, self.classifier = self.create_acne_inference(acne_infer_config)def run(self):import multiprocessingprint("进入子进程区域后:")process_info = multiprocessing.current_process()print(f"当前进程数量: {multiprocessing.cpu_count()}")print(f"当前进程编号: {process_info.name}")# 打印当前线程数量和编号thread_info = threading.current_thread()print(f"当前线程数量: {threading.active_count()}")print(f"当前线程编号: {thread_info.name}")from Docx import GenerateDocximport osimport cv2import mathimport utilsimport numpy as npfrom docx2pdf import convertfrom mmdeploy_runtime import Detector, Classifierfrom infer_config import acne_infer_configdef create_acne_inference(cfg):QApplication.processEvents()self.detector = Detector(model_path=cfg['detector']['model_path'],device_name=cfg['detector']['device_name'],device_id=cfg['detector']['device_id'])QApplication.processEvents()self.classifier = Classifier(model_path=cfg['classifier']['model_path'],device_name=cfg['classifier']['device_name'],device_id=cfg['classifier']['device_id'])QApplication.processEvents()return self.detector, self.classifierdef acne_instance_seg(img: np.ndarray, detector: Detector):QApplication.processEvents()win_gen = utils.WindowGenerator(img.shape[0], img.shape[1],INFER_WINDOW_SIZE[0], INFER_WINDOW_SIZE[1],INFER_WINDOW_STRIDES[0], INFER_WINDOW_STRIDES[1])QApplication.processEvents()p_bboxes, p_labels, p_masks = [], [], []for h_slice, w_slice in win_gen:QApplication.processEvents()img_patch = img[h_slice, w_slice, :]offset_x, offset_y = w_slice.start, h_slice.startb, l, m = detector(img_patch)b[:, [0, 2]] += offset_xb[:, [1, 3]] += offset_yp_bboxes.append(b)p_labels.append(l)p_masks.extend(m)p_bboxes = np.concatenate(p_bboxes, axis=0)p_labels = np.concatenate(p_labels, axis=0)p_masks = np.array(p_masks, dtype=object)bboxes, labels, masks = [], [], []cls = np.unique(p_labels)for c in cls:QApplication.processEvents()idx = p_labels == cb = p_bboxes[idx]l = p_labels[idx]m = p_masks[idx]keep = utils.nms(b, OVERLAP_NMS_THRESHOLD)bboxes.append(b[keep])labels.append(l[keep])masks.append(m[keep])bboxes = np.concatenate(bboxes, axis=0)labels = np.concatenate(labels, axis=0)masks = np.concatenate(masks, axis=0)return bboxes, labels, masksdef acne_severity_grading(img: np.ndarray, classifier: Classifier):result = classifier(img)return resultfrom infer_config import acne_infer_configdetector, classifier = create_acne_inference(acne_infer_config)# 执行耗时的任务print("开始处理图片")QApplication.processEvents()# 模拟耗时的任务#    '''人脸严重程度分级'''grading_result = 0 # 从1开始的痤疮等级# count = 0# 判断是否选择了图片if len(self.selected_imgPaths)== 0:print("未选择图片")returnfor i in range(len(self.selected_imgPaths)):QApplication.processEvents()# count = i+1# self.label_showResult.setText(f'正在检测第{count}张图片')# self.label_condition.setText(f'请耐心等待,正在检测第{count}张图片')image = cv2.imread(self.selected_imgPaths[i])QApplication.processEvents()# self.detector, self.classifier = self.create_acne_inference(acne_infer_config)QApplication.processEvents()bboxes, labels, masks = acne_instance_seg(image, detector)QApplication.processEvents()cls_result = acne_severity_grading(image, classifier)QApplication.processEvents()grading_result = cls_result[0][0]+1indices = [i for i in range(len(bboxes))]QApplication.processEvents()category_count = {   'papule':0,'nevus':0,'nodule':0,'open_comedo':0,'closed_comedo':0,'atrophic_scar':0,'hypertrophic_scar':0,'melasma':0,'pustule':0,'other':0}for index, bbox, label_id in zip(indices, bboxes, labels):QApplication.processEvents()# print(count,index,bbox,label_id)[left, top, right, bottom], score = bbox[0:4].astype(int), bbox[4]if score < BBOX_DISPLAY_CONFIDENCE:continuecolor = CATEGORY_COLOR[CATEGORY_INDEX[label_id]]cv2.rectangle(image, (left, top), (right, bottom), color)label_text = f"{CATEGORY_INDEX[label_id]} | {int(100 * score)}%"  # 使用痤疮的标签作为标注信息cv2.putText(image, label_text, (left, top - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 1)  # 添加标注信息if masks[index].size:mask = masks[index]if mask.shape == image.shape[:2]:  # rtmdet-instmask_img = image.copy()else:  # maskrcnnx0 = int(max(math.floor(bbox[0]) - 1, 0))y0 = int(max(math.floor(bbox[1]) - 1, 0))mask_img = image[y0:y0 + mask.shape[0], x0:x0 + mask.shape[1]]mask_img[mask.astype(bool)] = colorcategory_count[CATEGORY_INDEX[label_id]] += 1text = f'Prediction: {cls_result[0][0]}, {cls_result[0][1]:.4f} ' \f'({acne_infer_config["classifier"]["classes"][cls_result[0][0]]})'cv2.putText(image, text, (20, 40), cv2.FONT_HERSHEY_SIMPLEX, 1.0, (255, 255, 255), 2)img_name = os.path.splitext(os.path.basename(self.selected_imgPaths[i]))[0]# from datetime import datetime# # 获取当前日期和时间# now = datetime.now()# 提取年、月和日year = self.now.yearmonth = self.now.monthday = self.now.daygenerated_image_path = f"./result/{img_name}_report_{year}_{month}_{day}.jpg"cv2.imwrite(generated_image_path , image)self.generated_image_paths.append(generated_image_path)closed_comedo_count = category_count['closed_comedo']open_comedo_count = category_count['open_comedo']papule_count = category_count['papule']pustule_count = category_count['pustule']nodule_count = category_count['nodule']atrophic_scar_count = category_count['atrophic_scar']hypertrophic_scar_count = category_count['hypertrophic_scar']melasma_count = category_count['melasma']nevus_count = category_count['nevus']other_count = category_count['other']self.text[img_name] = {"grading_result":grading_result,"category_count":{"closed_comedo":closed_comedo_count,"open_comedo":open_comedo_count,"papule":papule_count,"pustule":pustule_count,"nodule":nodule_count,"atrophic_scar":atrophic_scar_count,"hypertrophic_scar":hypertrophic_scar_count,"melasma":melasma_count,"nevus":nevus_count,"other":other_count}}'''生成报告'''#必须先生成docx文件再生成pdf文件,我的docx文件和产生的结果图片保存在同一个位置的grading_result = self.text[img_name]["grading_result"]category_count = self.text[img_name]["category_count"]docx_generate = GenerateDocx(generated_image_path,'./result',grading_result,category_count)generated_docxFilePath = docx_generate.predict()self.generated_docxFilePath_List.append(generated_docxFilePath)self.q.put(self.generated_image_paths)self.q.put(self.generated_docxFilePath_List)self.q.put(self.text)

运行截图

“打开图片时”:

“进入子进程前”:

“子进程join前”:

“进入子进程区域后”:

“子进程join后”:

“进入子线程区域后”:

实验感悟

当前环境进程本来就有8个,在创建进程的时候没有增添多的进程的数量,说明我自己在创建子进程知识激活了当前环境下休闲的进程。

当切换进程时,进程的编号从“MainProcess”变为“Workler-1”,当前线程的编号没有变,还是“MainThread”,当启动当前进程的第二个线程的时候,子线程的编号变为“Thread-1”。

当第二次、第三次打开图片并运行的时候,实验运行结果为:

当第四次打开图片比选哪个运行的时候,GUI程序退出,但是子进程仍然在执行

当前线程的编号变的很大,为“Thread-8”,说明进程线程开启的太多了,超过了负荷。

但是后续实验好像证明:子进程、子线程执行完任务会自动退出,只是创建的进程线程的编号变了,并没有创建新的进程线程

 GUI自动退出后,再次启动程序

运行结果和初步试验的结果相同,说明主进程退出后,子进程、子线程同步退出

 后续实验展望:

在使用第二个进程,和第二个线程的时候,应该采取什么办法来使得销毁或者释放当前进程和线程,使得第三次使用子进程,子线程的时候还是第二个进程和线程。

后续实验证明:子进程、子线程执行完任务后会自动退出。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/414220.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

SPI传感器接口设计与优化:基于STM32的实践

SPI&#xff08;串行外设接口&#xff09;是一种常用的串行通信协议&#xff0c;用于在微控制器和外部设备之间进行全双工的高速数据传输。在本文中&#xff0c;我们将探讨如何基于STM32微控制器设计和优化SPI传感器接口&#xff0c;并提供相应的代码示例。 1. SPI传感器接口设…

Github 2024-01-16 Python开源项目日报 Top10

根据Github Trendings的统计&#xff0c;今日(2024-01-16统计)共有10个项目上榜。根据开发语言中项目的数量&#xff0c;汇总情况如下&#xff1a; 开发语言项目数量Python项目10HTML项目1 精心策划的Python资源列表 创建周期&#xff1a;3490 天开发语言&#xff1a;Python…

Ubuntu20.04安装配置OpenCV-Python库并首次执行读图

一、选择三方提供的预编译包安装&#xff1a; 可以从官网下载 OpenCV 的安装包&#xff0c;编译后使用&#xff1b;也可以直接使用第三方提供的预编译包 安装。显然后者不需要执行编译步骤&#xff0c;更便捷。选择由 PyPI 提供的 OpenCV 安装包&#xff0c;可以在 https://py…

Springboot日志框架logback与log4j2

目录 Springboot日志使用 Logback日志 日志格式 自定义日志格式 日志文件输出 Springboot启用log4j2日志框架 Springboot日志使用 Springboot底层是使用slf4jlogback的方式进行日志记录 Logback日志 trace&#xff1a;级别最低 debug&#xff1a;调试级别的&#xff0c…

获取域控的方法

在域渗透中、作为渗透测试人员&#xff0c;获取域控的权限基本上可以获取整个内网的权限 1.高权限读取本地密码 当域管理员在域成员机器上登录进行工作的时候&#xff0c;会将明文密码保存在本地进行的lsass.exe&#xff0c;可以通过 mimikatz来读取到本地的明文密码。 priv…

【Java 设计模式】结构型之适配器模式

文章目录 1. 定义2. 应用场景3. 代码实现结语 适配器模式&#xff08;Adapter Pattern&#xff09;是一种结构型设计模式&#xff0c;用于将一个类的接口转换成客户端期望的另一个接口。这种模式使得原本由于接口不兼容而不能一起工作的类可以一起工作。在本文中&#xff0c;我…

确保您的计算机符合SOLIDWORKS 2024的最低系统配置要求

在现代工程和设计领域中&#xff0c;SOLIDWORKS 2024 成为了许多专业人士首选的三维建模软件。然而&#xff0c;要确保您充分发挥其潜力&#xff0c;首先需要确保您的计算机符合 SOLIDWORKS 2024 的最低系统要求。本文将为您提供关于系统要求的详细信息&#xff0c;以确保您的工…

多标签节点分类

Multi-Label Node Classification on Graph-Structured Data,TMLR’23 Code 学习笔记 图结构数据的多标签分类 节点表示或嵌入方法 通常会生成查找表&#xff0c;以便将相似的节点嵌入的更近。学习到的表示用作各种下游预测模块的输入特征。 表现突出的方法是基于随机游走(ran…

71.网游逆向分析与插件开发-角色数据的获取-修复角色名与等级显示问题

内容参考于&#xff1a;易道云信息技术研究院VIP课 上一个内容&#xff1a;自动化助手UI显示角色数据-CSDN博客 码云地址&#xff08;ui显示角色数据 分支&#xff09;&#xff1a;https://gitee.com/dye_your_fingers/sro_-ex.git 码云版本号&#xff1a;0049452c079867779…

高级分布式系统-第15讲 分布式机器学习--神经网络理论

高级分布式系统汇总&#xff1a;高级分布式系统目录汇总-CSDN博客 神经网络理论 模糊控制在处理数值数据、自学习能力等方面还远没有达到人脑的境界。人工神经网络从另一个角度出发&#xff0c;即从人脑的生理学和心理学着手&#xff0c;通过人工模拟人脑的工作机理来实现机器…

Microsoft Word 删除空行

Microsoft Word 删除空行 1. 删除空行1.1. 替换1.2. 段落标记 References 1. 删除空行 1.1. 替换 1.2. 段落标记 特殊格式 -> 段落标记 References [1] Yongqiang Cheng, https://yongqiang.blog.csdn.net/

大数据StarRocks(八):集群扩缩容

一、FE扩缩容 StarRocks FE 节点分为 Follower 节点和 Observer 节点。Follower 节点参与选举投票和写入&#xff0c;Observer 节点只用来同步日志&#xff0c;扩展读性能。 注意&#xff1a; 所有 FE 节点的 http_port 必须相同。Follower FE 节点&#xff08;包括 Leader …