summaryrefslogtreecommitdiff
path: root/tsp.py
diff options
context:
space:
mode:
Diffstat (limited to 'tsp.py')
-rwxr-xr-xtsp.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/tsp.py b/tsp.py
index ba510a5..5530fb0 100755
--- a/tsp.py
+++ b/tsp.py
@@ -380,6 +380,16 @@ is called.'''
self.best = path
self.update_best (path = self.best)
+ def resume (self):
+ '''Resume thread: since we can't start a Thread twice, let's copy
+its data into a new Thread, start the new one and return it'''
+ thread = AlgoThread (self.context, self.algo, self.gui, self.canvas,
+ self.init)
+ thread.runner = self.runner
+ thread.best = self.best
+ thread.start ()
+ return thread
+
def stop (self):
'''Stop thread'''
self.terminate = True
@@ -561,12 +571,7 @@ class AlgoGui (gtk.Window):
'''Resume algorithm execution'''
if not self.thread or self.thread.isAlive ():
return
- thread = AlgoThread (self.context, self.algo, self, self.canvas,
- init = self.get_init ())
- thread.runner = self.thread.runner
- thread.best = self.thread.best
- self.thread = thread
- self.thread.start ()
+ self.thread = self.thread.resume ()
self.gen_button.set_sensitive (False)
self.start_button.set_sensitive (False)
self.resume_button.set_sensitive (False)