I am creating a small GUI where user clicks a push button so the numerical simulation code in FORTRAN starts and its execution is shown with busy indicator movement (front and back).
With pool.apply_async method I could able to run the FORTRAN code and busy indicator successfully. But I have a problem when I stop the process and restart it. When I restart the process, it is not running and throwing an assertion error. (assert self._state == RUN)
Note: I am not supposed to disturb the FORTRAN code at any moment. Because it is a fixed one written for some numerical simulation. Its execution takes more than 30 mins
Below is my code:
import sys
from PyQt4 import QtGui
from PyQt4 import QtCore
from PyQt4 import uic
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import FortranSimulation
import time
qtCreatorFile = "you_atmpt.ui" # Loading UI file
Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile)
def pass_args(args):
b = 10.0
print b
b = b + 2
FortranSimulation.fortrancode(b)
return b
class MainClass(QtGui.QMainWindow,Ui_MainWindow): # MAin GUI class
def __init__(self):
super(MainClass,self).__init__()
self.setupUi(self) # 2 PB
self.StartCalculaltion_button.clicked.connect(self.Fortran_Calc)
self.Stop_button.clicked.connect(self.Stop_All)
self.pool = mp.Pool(None)
def Fortran_Calc(self):# Initiation of other process for 'Fortran Calculation'
self.label_2.setText('Calculation is in progress!')
self.progressBar.setRange(0,0)
index = 1
surface_id = 2
self.pool.apply_async(pass_args, [(surface_id, index)],
callback=self.callback)
def callback(self,b):
print b
self.label.setText('Calculation is completed!')
def Stop_All(self): # Termination of process
self.progressBar.setRange(0,1)
self.pool.close()
self.pool.terminate()
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
window = MainClass()
window.show()
app.exec_()
I added the error message also:
I tried with self.pool.close(), self.pool.terminate() these commands are stopping the process. At the same time I can't restart the process again with the start button.
And also I would like to know whether restarting a process is possible or not?
Thanks in advance.