diff --git a/GPy/__init__.py b/GPy/__init__.py index f35fda78..5c4838da 100644 --- a/GPy/__init__.py +++ b/GPy/__init__.py @@ -2,6 +2,7 @@ # Licensed under the BSD 3-clause license (see LICENSE.txt) import warnings warnings.filterwarnings("ignore", category=DeprecationWarning) +import os import core import models @@ -19,3 +20,20 @@ from core import priors @nottest def tests(): Tester(testing).test(verbose=10) + +if os.name == 'nt': + """ + Fortran seems to like to intercept keyboard interrupts on windows. + This means that when a model is optimizing and the user presses Ctrl-C, + the program will crash. Since it's kind of nice to be able to stop + the optimization at any time, we define our own handler below. + + """ + import win32api + import thread + + def handler(sig, hook=thread.interrupt_main): + hook() + return 1 + + win32api.SetConsoleCtrlHandler(handler, 1)