Skip to content

Commit

Permalink
Merge pull request EpistasisLab#397 from weixuanfu2016/fix_bug_in_thread
Browse files Browse the repository at this point in the history
Timeout decorators now works with python 2.* in Windows
  • Loading branch information
rhiever authored Mar 30, 2017
2 parents e315a21 + 7cd45d1 commit a06a388
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions tpot/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"""

from __future__ import print_function
from threading import Thread, current_thread
import threading
from functools import wraps
import sys
import warnings
Expand Down Expand Up @@ -88,19 +88,21 @@ def limitedTime(*args, **kw):
signal.alarm(0) # Alarm removed
return ret
else:
class InterruptableThread(Thread):
class InterruptableThread(threading.Thread):
def __init__(self, args, kwargs):
Thread.__init__(self)
threading.Thread.__init__(self)
self.args = args
self.kwargs = kwargs
self.result = -float('inf')
self._stopevent = threading.Event()
self.daemon = True
def stop(self):
self._stop()
self._stopevent.set()
threading.Thread.join(self)
def run(self):
# Note: changed name of the thread to "MainThread" to avoid such warning from joblib (maybe bugs)
# Note: Need attention if using parallel execution model of scikit-learn
current_thread().name = 'MainThread'
threading.current_thread().name = 'MainThread'
with warnings.catch_warnings():
warnings.simplefilter('ignore')
self.result = func(*self.args, **self.kwargs)
Expand Down

0 comments on commit a06a388

Please sign in to comment.