W
W
Warlam2021-07-03 20:00:39
Python
Warlam, 2021-07-03 20:00:39

Multiple infinite loops in python?

Sorry for the dumb question, I'm new. I am making a parser (sends a request to the server, receives a response and writes it to the table at the click of a button). The data must be updated dynamically (that's why I have the parsing function in an infinite loop). Everything hangs. Used multiprocessing. Maybe I wrote something wrong, maybe it's just impossible to do it that way. Tell me what you can think of

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

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ronald McDonald, 2021-07-03
@Warlam

In any infinite loop, there must be a forced exit on the brake. Check if you have it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question