@Warlam

Проблема с multiprocessing?

При запуске процесса(stavka) в функции btnClicked_2 выводит ошибки:
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\.....\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 116, in spawn_main
exitcode = _main(fd, parent_sentinel)
File "C:\Users\....\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 126, in _main
self = reduction.pickle.load(from_parent)
EOFError: Ran out of input
Заранее извините за код, я новичок
Code

url = '.....'

user_agent_val = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36'

place = -1

procs = ['','','','','','','','','','','','','','','','','','','','']

session = requests.Session()

header = {
    'user-agent':user_agent_val
}

Bool = False

class mywindow(QtWidgets.QMainWindow):
    def __init__(self):
        super(mywindow, self).__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.ui.pushButton.clicked.connect(self.btnClicked)
        self.ui.pushButton_2.clicked.connect(self.btnCkicked_2)
        self.ui.pushButton_3.clicked.connect(self.btnCkicked_3)

        row = 0
        for i in range(19):
            col = 0
            for j in range(4):
                # Только для чтения
                self.ui.tableWidget.item(i,j).setFlags(
                    QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled
                )
                col += 1
            row += 1

    def stavka(self, AuctionID_raw, Price, data3, AuctionID, place):
        Bool = False
        while True:
            nextcost = ""

            Endtime = ""

            lastbetcost = ""

            rowVersion = ""

            name = ""

            response3 = session.get(AuctionID, data=data3, headers=header).text

            z = response3.find("lastBetSupplier")

            for z in range(z - 1, z + 37):
                name = name + response3[z]

            j = response3.find("rowVersion") + 13

            for j in range(j, j + 12):
                rowVersion = rowVersion + response3[j]

            i = response3.find("nextCost") + 10

            while response3[i].isdigit() or response3[i] == ".":
                nextcost = nextcost + response3[i]
                i = i + 1

            o = response3.find("lastBetCost") + 13

            while response3[o].isdigit() or response3[o] == ".":
                lastbetcost = lastbetcost + response3[o]
                o = o + 1

            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)  # Random date in the past
            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 = "Неактивно"
            else:
                status = "Активно"

            if Price < nextcost_d and name != '"lastr":{"...':
                data4 = {
                    'ausio': 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)
                    tabl.append(lastbetcost)
                    tabl.append(Price)
                    tabl.append(TimeLeft)
                    tabl.append(status)
                    self.ui.label_6.setText(".....")
                else:
                    Bool = False
            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(str(item))
                self.ui.tableWidget.setItem(place, col, cellinfo)
                col += 1
            time.sleep(5)

    def btnClicked(self):
        login = self.ui.lineEdit.text()
        password = self.ui.lineEdit_2.text()

        data1 = {
            'type': 'Password'
        }

        response1 = session.get('......', data=data1, headers=header).text.replace('"', '')

        data = {
            'token': response1,
            'operation': 'LogIn',
            'argument': {'values': {'login': login, 'password': password}}
        }

        response = session.post(url, json=data, headers=header).text

        if response == '{"isSessionComplete":true,"values":{"sessionFailed":"true","message":"Неверный логин или пароль"}}':
            self.ui.lineEdit_3.setText("Неверный логин или пароль")
        else:
            self.ui.lineEdit_3.setText("Авторизация прошла успешно")
    def btnCkicked_2(self):

        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

        if __name__ == '__main__':
            proc = Process(target=self.stavka ,args=(self,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(4):
                self.ui.tableWidget.item(number,i).setText('')
        else:
            return False

if __name__=='__main__':
    app = QtWidgets.QApplication([])
    application = mywindow()
    application.show()
    sys.exit(app.exec())

  • Вопрос задан
  • 79 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы