是这样的,我在开发一个给开客户用的批量订购小应用。基于Python Pyside6
在做多节点询价的时候希望用多线程实现快速询价,以及后续的订购。
@Slot()
def queryPrice(self):
checkedbox = []
for i in self.checkboxlist:
if i.isChecked():
checkedbox.append(i)
if len(checkedbox) == 0 :
QMessageBox.information(self,"提示","请优先勾选节点")
else:
self.ui.textEditArea.setMarkdown(self.ui.textEditArea.toMarkdown() + "⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐")
# queryPriceClient = VmqueryPriceSample
# request = VmqueryPriceRequest
# self.pool.map(self.multiquerypricetask,checkedbox)
** pool = Pool(processes=8)
pool.map(self.multiquerypricetask,checkedbox)**
# self.multiquerypricetask(checkedbox)
self.ui.textEditArea.setMarkdown(self.ui.textEditArea.toMarkdown() + "⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐")
self.ui.queryPriceBtn.setEnabled(False)
def multiquerypricetask(self,checkedcity):
# for checkedcity in checkedbox:
ak = self.ui.acccesskeyLineEdit.text().strip()
sk = self.ui.secretkeyLineEdit.text().strip()
client = VmCreateapiSample.create_client(ak, sk, self.rgnCheckboxdict[checkedcity])
request = VmqueryPriceRequest()
boot_volume = VmqueryPriceRequestBootVolume()
vmquery_price_body = VmqueryPriceBody()
vmquery_price_body.product_type = "vm"
if self.ui.bootVolumeTypeComboBox.currentText() == "高性能型硬盘":
boot_volume.volume_type = "highPerformance"
else:
boot_volume.volume_type = "performanceOptimization"
if self.ui.billingTypeComboBox.currentText() == "按月支付(包月)":
vmquery_price_body.fee_unit = "month"
elif self.ui.billingTypeComboBox.currentText() == "按年支付(包年)":
vmquery_price_body.fee_unit = "year"
else:
vmquery_price_body.fee_unit = "hour"
boot_volume.size = int(self.ui.bootVolumeSizeLineEdit.text())
vmquery_price_body.duration = int(self.ui.durationSpinBox.value())
vmquery_price_body.boot_volume = boot_volume
vmquery_price_body.quantity = int(self.ui.quantitySpinBox.value())
vmquery_price_body.specs_name = self.ui.specsNameLineEdit.text().strip()
request.vmquery_price_body = vmquery_price_body
print("%s节点开始询价" % (self.realnamedict[checkedcity]))
res = client.vmquery_price(request)
if res.body != None:
price = float(res.body.server_price) + float(
res.body.boot_volume_price)
print("%s节点询价完毕"%(self.realnamedict[checkedcity]))
self.showMsgIntextArea("----------%s节点该配置价格为 %.2f元(只包含云主机和硬盘价格)" % (
self.realnamedict[checkedcity], price))
else:
print("%s节点询价失败" % (self.realnamedict[checkedcity]))
self.showMsgIntextArea("----------%s节点询价失败。原因:%s" % (
self.realnamedict[checkedcity], res.error_message))
报错如下:华东-杭州节点开始询价华南-广州节点开始询价
华南-广州节点询价完毕
Process finished with exit code -1073741819 (0xC0000005)
广州节点询价完毕后程序直接没了
希望各位能分析下,这是什么原因。关键代码部分已经加粗了。刚接触到多线程。。
再次感谢
** pool = Pool(processes=8)
pool.map(self.multiquerypricetask,checkedbox)**
这两行~