Changeset: e9aefb4fc944 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e9aefb4fc944
Modified Files:
        testing/Mtest.py.in
        testing/process.py
        tools/mserver/mserver5.c
Branch: default
Log Message:

On Windows, jump through hoops to gently terminate server.
process.terminate() hard kills the process which we don't want, since
output may not have been flushed.  So create new console group for
server and send a CTRL-BREAK to it when we want the server to exit.
This is then caught by the server which dutifully exits.


diffs (102 lines):

diff --git a/testing/Mtest.py.in b/testing/Mtest.py.in
--- a/testing/Mtest.py.in
+++ b/testing/Mtest.py.in
@@ -2831,8 +2831,13 @@ def LaunchIt(cmd, TestOut, TestErr, Time
     if procdebug:
         print('LaunchIt: starting process "%s" (inpipe)\n' % '" "'.join(cmd))
     setpgrp = True
-    proc = process.Popen(cmd, stdin=open(os.devnull), stdout=SrvrOut,
-                         stderr=TestErr, universal_newlines=True)
+    if os.name == "nt":
+        proc = process.Popen(cmd, stdin=open(os.devnull), stdout=SrvrOut,
+                             stderr=TestErr, universal_newlines=True,
+                             creationflags=process.CREATE_NEW_PROCESS_GROUP)
+    else:
+        proc = process.Popen(cmd, stdin=open(os.devnull), stdout=SrvrOut,
+                             stderr=TestErr, universal_newlines=True)
     # maybe buffer output as it comes to avoid deadlock
     if SrvrOut == process.PIPE:
         proc.stdout = process._BufferedPipe(proc.stdout)
@@ -3224,7 +3229,10 @@ def DoIt(env, SERVER, CALL, TST, EXT, PR
 
         if SERVER in ["MAL", "SQL"]:
             if ServerReady:
-                pSrvr.terminate()
+                if os.name == "nt":
+                    pSrvr.send_signal(signal.CTRL_BREAK_EVENT)
+                else:
+                    pSrvr.terminate()
 
             CollectIt(pSrvr.stdout, SrvrOut)
             pSrvr.wait()
diff --git a/testing/process.py b/testing/process.py
--- a/testing/process.py
+++ b/testing/process.py
@@ -19,8 +19,15 @@ else:
     import queue
 
 from subprocess import PIPE
+__all__ = ['PIPE', 'Popen', 'client', 'server']
 
-__all__ = ['PIPE', 'Popen', 'client', 'server']
+try:
+    # on Windows, also make this available
+    from subprocess import CREATE_NEW_PROCESS_GROUP
+except ImportError:
+    pass
+else:
+    __all__.append('CREATE_NEW_PROCESS_GROUP')
 
 verbose = False
 
diff --git a/tools/mserver/mserver5.c b/tools/mserver/mserver5.c
--- a/tools/mserver/mserver5.c
+++ b/tools/mserver/mserver5.c
@@ -237,6 +237,20 @@ static void emergencyBreakpoint(void)
 
 static volatile sig_atomic_t interrupted = 0;
 
+#ifdef _MSC_VER
+static BOOL
+winhandler(DWORD type)
+{
+       (void) type;
+#ifdef HAVE_CONSOLE
+       if (!monet_daemon)
+               _Exit(-1);
+       else
+#endif
+               interrupted = 1;
+       return TRUE;
+}
+#else
 static void
 handler(int sig)
 {
@@ -248,6 +262,7 @@ handler(int sig)
 #endif
                interrupted = 1;
 }
+#endif
 
 int
 main(int argc, char **av)
@@ -623,6 +638,10 @@ main(int argc, char **av)
                }
        }
 #else
+#ifdef _MSC_VER
+       if (!SetConsoleCtrlHandler(winhandler, TRUE))
+               fprintf(stderr, "!unable to create console control handler\n");
+#else
        if(signal(SIGINT, handler) == SIG_ERR)
                fprintf(stderr, "!unable to create signal handlers\n");
 #ifdef SIGQUIT
@@ -632,6 +651,7 @@ main(int argc, char **av)
        if(signal(SIGTERM, handler) == SIG_ERR)
                fprintf(stderr, "!unable to create signal handlers\n");
 #endif
+#endif
 
        {
                str lang = "mal";
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to