A program that runs a bat file that contains instructions for running an executable file (longTask) using Qthread, but it does not work properly when I create an executable using Pyinstaller with the following command. I gave "--windowed" to not provide a console window for standard I / O
pyinstaller --onefile --windowed main.py
But the interesting thing is that this works, as expected, when I remove the argument
pyinstaller --onefile main.py
Here is the code:
from PyQt4.Qt import *
import subprocess
def callSubprocess():
page = QWizardPage()
page.setTitle("Run myLongTask")
runButton = QPushButton("Run")
progressBar = QProgressBar()
procLabel = QLabel()
procLabel1 = QLabel()
progressBar.setRange(0, 1)
layout = QGridLayout()
layout.addWidget(runButton, 0, 0)
layout.addWidget(progressBar, 0, 1)
layout.addWidget(procLabel)
layout.addWidget(procLabel1)
myLongTask = TaskThread()
runButton.clicked.connect(lambda: OnStart(myLongTask, progressBar, procLabel1))
myLongTask.taskFinished.connect(lambda: onFinished(progressBar, procLabel))
page.setLayout(layout)
return page
def OnStart(myLongTask, progressBar, procLabel1):
progressBar.setRange(0, 0)
myLongTask.start()
while not myLongTask.isFinished():
QCoreApplication.processEvents()
procLabel1.setText("Hello This is main")
def onFinished(progressBar, procLabel):
progressBar.setRange(0, 1)
procLabel.setText("longTask finished")
class TaskThread(QThread):
taskFinished = pyqtSignal()
def __init__(self):
QThread.__init__(self)
def run(self):
proc = subprocess.Popen(r'C:\Users\Desktop\runInf.bat', bufsize=0, shell=True, stdout=subprocess.PIPE)
proc.wait()
self.taskFinished.emit()
def __del__(self):
self.wait()
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
wizard = QWizard()
wizard.addPage(callSubprocess())
wizard.setWindowTitle("Example Application")
wizard.show()
sys.exit(wizard.exec_())
When executing the above code in Pycharm, it works as expected. But when building with PyInstaller, the main thread does not wait for the subprocess to complete.
Any idea of creating an executable when the threads are working as expected. thanks in advance
source