From 69ba955d5c49420ddf32b6be6bf1894556b43396 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@uliege.be>
Date: Tue, 7 Jul 2020 16:56:19 +0200
Subject: [PATCH] check for oldsig == None (cf. #918)

---
 api/GenApi.py | 3 ++-
 api/gmsh.py   | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/api/GenApi.py b/api/GenApi.py
index 5729c0aba5..ec17869232 100644
--- a/api/GenApi.py
+++ b/api/GenApi.py
@@ -1400,7 +1400,8 @@ class API:
                         tuple((a.python_arg
                                for a in args)) + ("byref(ierr)", )) + ")\n")
             if name == "finalize": # special case for finalize() function
-                f.write(indent + "signal.signal(signal.SIGINT, oldsig)\n")
+                f.write(indent + "if oldsig is not None:\n")
+                f.write(indent + "    signal.signal(signal.SIGINT, oldsig)\n")
             f.write(indent + "if ierr.value != 0:\n")
             if name == "getLastError": # special case for getLastError() function
                 f.write(indent + "    raise Exception('Could not get last error')\n")
diff --git a/api/gmsh.py b/api/gmsh.py
index ad660e6418..13ad4c7f95 100644
--- a/api/gmsh.py
+++ b/api/gmsh.py
@@ -210,7 +210,8 @@ def finalize():
     ierr = c_int()
     lib.gmshFinalize(
         byref(ierr))
-    signal.signal(signal.SIGINT, oldsig)
+    if oldsig is not None:
+        signal.signal(signal.SIGINT, oldsig)
     if ierr.value != 0:
         raise Exception(logger.getLastError())
 
-- 
GitLab