alouha2333 2022-05-07 16:24 采纳率: 100%
浏览 61
已结题

PYQT ThreadPoolExecutor 程序打包

PYQT ThreadPoolExecutor 程序打包
在pychram中能正常打开,打包后能正常进入UI界面,但无法运行主程序,系统也没有报错。单独测试过控件能正常触发。

import os
import sys
import threading
from concurrent.futures import ThreadPoolExecutor, wait, ALL_COMPLETED
from time import sleep
import pandas as pd
import win32api
import win32con
from PyQt5.QtCore import QSettings, QThread
from PyQt5.QtWidgets import QMainWindow, QApplication


from untitled import Ui_MainWindow


class Thread_1(QThread):  # 线程1
    def __init__(self):
        super().__init__()

    def run(self):
        AccountLogin.begin()


class CUi_MainWindow(QMainWindow, Ui_MainWindow):  # 继承于UI父类
    def __init__(self, parent=None):
        super(CUi_MainWindow, self).__init__(parent)
        self.setupUi(self)
        self.init_login_info()
        self.pushButton.clicked.connect(self.start)
        self.pushButton_2.clicked.connect(self.pause)

    def save(self):
        settings = QSettings("config.ini", QSettings.IniFormat)
        settings.setValue("excl_path", self.lineEdit.text())
        settings.setValue("share_path", self.lineEdit_2.text())
        settings.setValue("ld_path", self.lineEdit_3.text())
        settings.setValue("thread", self.lineEdit_4.text())


    def init_login_info(self):
        settings = QSettings("config.ini", QSettings.IniFormat)
        ld_path = settings.value("ld_path")
        share_path = settings.value("share_path")
        excl_path = settings.value("excl_path")
        pause = settings.value("pause")
        thread=settings.value("thread")
        if str(pause) == "恢复":
            self.pushButton_2.setText("暂停")
        elif str(pause) == "暂停":
            settings.setValue("pause", "恢复")
            self.pushButton_2.setText("暂停")
        self.lineEdit.setText(excl_path)
        self.lineEdit_2.setText(share_path)
        self.lineEdit_3.setText(ld_path)
        self.lineEdit_4.setText(thread)


    def start(self):
        self.save()
        self.thread_1 = Thread_1()  # 创建线程
        self.thread_1.start()  # 开始线程



    def pause(self):
        settings = QSettings("config.ini", QSettings.IniFormat)
        text = self.pushButton_2.text()
        if str(text) == "暂停":
            self.pushButton_2.setText("恢复")
            settings.setValue("pause", "暂停")
        elif str(text) == "恢复":
            self.pushButton_2.setText("暂停")
            settings.setValue("pause", "恢复")


class Dnconsole:
    # 请根据自己电脑配置
    settings = QSettings("config.ini", QSettings.IniFormat)
    ld_path = str(settings.value("ld_path")).replace("\\", "/")
    SharePath = str(settings.value("share_path")).replace("\\", "/")
    console = ld_path + '/ldconsole.exe '
    ld = ld_path + '/ld.exe '
    share_path = SharePath

    @staticmethod
    def get_list():
        cmd = os.popen(Dnconsole.console + 'list2')
        text = cmd.read()
        cmd.close()
        info = text.split('\n')
        result = list()
        for line in info:
            if len(line) > 1:
                dnplayer = line.split(',')
                result.append(dnplayer)
        return result

    @staticmethod
    def invokeapp(index: int, package: str):
        cmd = Dnconsole.console + \
              'runapp --index %d --packagename %s' % (index, package)
        process = os.popen(cmd)
        result = process.read()
        process.close()
        print(result)
        return result

    @staticmethod
    def input_text(index: int, text: str):
        cmd = Dnconsole.console + \
              'action --index %d --key call.input --value %s' % (index, text)
        process = os.popen(cmd)
        result = process.read()
        process.close()
        return result

    @staticmethod
    def launch(index: int):
        cmd = Dnconsole.console + 'launch --index ' + str(index)
        process = os.popen(cmd)
        result = process.read()
        process.close()
        return result

    @staticmethod
    def quit(index: int):
        cmd = Dnconsole.console + 'quit --index ' + str(index)
        process = os.popen(cmd)
        result = process.read()
        process.close()
        return result

    @staticmethod
    def install(index: int):  # path: str
        # shutil.copy(path, Dnconsole.share_path + '/update.apk')
        sleep(1)
        Dnconsole.dnld(index, 'pm install /sdcard/Pictures/update.apk')

    # 卸载apk 指定模拟器必须已经启动

    @staticmethod
    def uninstall(index: int, package: str):
        cmd = Dnconsole.console + \
              'uninstallapp --index %d --packagename %s' % (index, package)
        process = os.popen(cmd)
        result = process.read()
        process.close()
        return result

    @staticmethod
    def dnld(index: int, command: str, silence: bool = False):
        cmd = Dnconsole.ld + '-s %d %s' % (index, command)
        if silence:
            os.system(cmd)
            return ''
        process = os.popen(cmd)
        result = process.read()
        process.close()
        return result


class AccountLogin:
    settings = QSettings("config.ini", QSettings.IniFormat)
    lock = threading.Lock()

    @staticmethod
    def Window_arrangement():
        cmd = Dnconsole.console + 'sortWnd'
        process = os.popen(cmd)
        process.close()

    @staticmethod
    def doClick(bind, x, y):  # 点击坐标
        AccountLogin.lock.acquire()
        cx=x*2
        cy=y*2
        long_position = win32api.MAKELONG(cx, cy)  # 模拟鼠标指针 传送到指定坐标
        win32api.SendMessage(bind, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, long_position)  # 模拟鼠标按下
        sleep(0.1)
        win32api.SendMessage(bind, win32con.WM_LBUTTONUP, win32con.MK_LBUTTON, long_position)  # 模拟鼠标弹起
        sleep(0.5)
        AccountLogin.lock.release()

    @staticmethod
    def accountLogin(i):
        excl_path = str(AccountLogin.settings.value("excl_path")).replace('\\', '/')
        excl_path1 = excl_path + "/enroll.xlsx"
        table = AccountLogin.settings.value("table")
        df = pd.read_excel(excl_path1, int(table))  # 读取项目名称列,不要列名
        df_li = df.values.tolist()
        index = int(i[0])
        Dnconsole.launch(index)
        AccountLogin.pause()
        sleep(20)
        AccountLogin.Window_arrangement()
        AccountLogin.pause()
        lis1 = Dnconsole.get_list()
        bind = lis1[index][3]
        lis2 = df_li[index]
        AccountLogin.pause()
        Dnconsole.uninstall(index, 'com.instagram.android')
        AccountLogin.pause()
        sleep(2)
        Dnconsole.install(index)
        AccountLogin.pause()
        sleep(2)
        Dnconsole.invokeapp(index, 'in.zhaoj.shadowsocksrr')
        AccountLogin.pause()
        sleep(5)
        AccountLogin.ClickWait(bind, 126, 23, 5)
        Dnconsole.invokeapp(index, 'com.instagram.android')
        AccountLogin.pause()
        sleep(20)
        AccountLogin.ClickWait(bind, 69, 132, 2)
        AccountLogin.ClickWait(bind, 50, 88, 2)
        Dnconsole.input_text(index, lis2[0])
        AccountLogin.pause()
        sleep(2)
        AccountLogin.ClickWait(bind, 65, 108, 2)
        Dnconsole.input_text(index, lis2[1])
        AccountLogin.pause()
        sleep(2)
        AccountLogin.ClickWait(bind, 72, 126, 5)
        Dnconsole.quit(index)

    @staticmethod
    def ClickWait(bind, x, y, time):
        AccountLogin.doClick(bind, x, y)
        AccountLogin.pause()
        sleep(time)

    @staticmethod
    def pause():
        while True:
            pause1 = AccountLogin.settings.value("pause")
            if str(pause1) == "恢复":
                break
            elif str(pause1) == "暂停":
                print("程序暂停中")
                sleep(1)
                continue

    @staticmethod
    def begin():
        lis = Dnconsole.get_list()
        thread = AccountLogin.settings.value("thread")
        executor = ThreadPoolExecutor(max_workers=int(thread))
        all_task = []
        for i in lis:
            executor.submit(AccountLogin.accountLogin, i)
            sleep(3)
        wait(all_task, return_when=ALL_COMPLETED)


if __name__ == "__main__":
    app = QApplication(sys.argv)
    mainWindow = CUi_MainWindow()
    mainWindow.show()
    sys.exit(app.exec())


回答的时候麻烦提供下思路和参考代码

  • 写回答

4条回答 默认 最新

  • 关注

    这种情况打包时打包成debug模式,在控制台查看程序报错或不能正常启动原因,之后返回打包配置文件修改

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 5月7日
  • 已采纳回答 5月7日
  • 创建了问题 5月7日

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题