From a749d31f8bda15bd3bb22afa2a6b7b4d5ab53896 Mon Sep 17 00:00:00 2001 From: Nicolo Fusi Date: Thu, 2 Jan 2014 01:39:31 -0800 Subject: [PATCH] fixed Ctrl-C behaviour on Windows --- GPy/__init__.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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)