Сразу извиняюсь за тупой вопрос, я новичок. Делаю парсер ( отправляет на сервер запрос, получает ответ и записывает в таблицу по клику кнопки). Данные должны динамически обновляться(поэтому функция парсинга у меня в бесконечном цикле). Все виснет. Пользовался multiprocessing. Возможно написал что-то не так, возможно просто так сделать невозможно. Подскажите, что можно придумать
def btnCkicked_2(self):
def stavka(AuctionID_raw, Price, data3, AuctionID, place):
Bool = False
while True:
Endtime = ""
rowVersion = ""
response3 = session.get(AuctionID, data=data3, headers=header).text
l = response3.find("endDate") + 10
while response3[l].isdigit() or response3[l] == "." or response3[l] == " " or response3[l] == ":":
Endtime = Endtime + response3[l]
l = l + 1
year = int(Endtime[6:10])
mounth = int(Endtime[3:5])
day = int(Endtime[0:2])
hour = int(Endtime[11:13])
min = int(Endtime[14:16])
sec = int(Endtime[17:19])
Endtime1 = datetime(year, mounth, day, hour, min, sec)
CurrentTime = datetime.now() # Now
duration = Endtime1 - CurrentTime # For build-in functions
duration_in_s = duration.total_seconds()
Timeleft1 = str(duration)
TimeLeft = Timeleft1[:-7]
if duration_in_s <= 0:
TimeLeft = "0 days, 00:00:00"
nextcost_d = float(nextcost)
if nextcost_d % 1 == 0:
nextcost_d = int(nextcost_d)
if TimeLeft == "0 days, 00:00:00":
status = Неактивно"
break
else:
status = "Активно"
if Price < nextcost_d and name != '"lastBetSupplier":{"name":"':
data4 = {
'auctionId': AuctionID_raw,
'rowVersion': rowVersion,
'value': nextcost_d
}
response2 = session.post('.....', json=data4,
headers=header)
if response2 == '<Response [200]>':
Bool = True
tabl = []
tabl.append(AuctionID_raw, lastbetcost, Price, TimeLeft, status)
self.ui.label.setText("...")
if not Bool:
self.ui.label_6.setText("....")
break
if Price > nextcost_d:
status = "...г"
break
tabl[0] = AuctionID
tabl[1] = lastbetcost
tabl[2] = Price
tabl[3] = TimeLeft
tabl[4] = status
col = 0
for item in tabl:
cellinfo = QTableWidgetItem(item)
self.ui.tableWidget.setItem(place, col, cellinfo)
col += 1
time.sleep(5)
AuctionID_raw = self.ui.lineEdit_4.text()
string = self.ui.lineEdit_5.text()
if string.isdigit() :
Price = float(self.ui.lineEdit_5.text())
else:
return False
data3 = {
'auctionid': AuctionID_raw
}
AuctionID = '.....' + AuctionID_raw
global procs
for i in range(20):
if self.ui.tableWidget.item(i,0).text() == "":
place = i
proc = stavka(AuctionID_raw, Price, data3, AuctionID, place)
procs[place] = proc
proc.start()
def btnCkicked_3(self):
global procs
number = int(self.ui.comboBox.currentText())
number = number - 1
if self.ui.tableWidget.item(number,0).text() != '':
procs[number].terminate()
for i in range(5):
self.ui.tableWidget.item(number,i).setText('')
else:
return False