0

I am making a genetic algorithm program that can go on forever but I want the user to be able to stop and start the execution at will. My idea was to have a button that sets a bool value that is checked at the final stage of the generation creation and if False the execution stops but keeps everything as it is so it can be continued from where it was paused however I do not know how to implement it such that I can interact with my programs UI and thus emit the signal to change the boolean.

Is the only way to do this by using a thread? I am not really sure how to use them specifically but I could learn. If this is the recommended method should I use QThread or just normal python threading? Will this cause a noticeable slow down of my program?

John O'Neil
  • 355
  • 1
  • 5
  • 15
  • Yes, the only way is using a thread. After all you want to process user interactions and your own computations at the same time! There are plenty of resources and questions here available for QThread and other threadings. And it will not cause a noticeable slow down. – NoDataDumpNoContribution Jan 16 '17 at 08:01
  • Possible duplicate of [Background thread with QThread in PyQt](http://stackoverflow.com/questions/6783194/background-thread-with-qthread-in-pyqt) – NoDataDumpNoContribution Jan 16 '17 at 08:02
  • Sorry for the duplicate but I have already written a large portion of my code and now I do not know how to switch it to use a thread. If I have everything working in my main window class. Most of the widgets should be harmless during operation but I want to be able to use the exit, stop and pause buttons normally. The main work starts when I call a function 'run' I can't work out how to separate that work from the GUI work. Also the run function uses another function with a loop that checks a variable 'running' and then does the next iteration of work from another class – John O'Neil Jan 16 '17 at 16:35
  • @JohnO'Neil. Nobody can help you any further unless you show some actual code. Please read the guidance on how to produce a [mcve]. – ekhumoro Jan 16 '17 at 18:34

0 Answers0