fixed Ctrl-C behaviour on Windows

This commit is contained in:
Nicolo Fusi 2014-01-02 01:39:31 -08:00
parent 45f76cc532
commit a749d31f8b

View file

@ -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)