Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Register
  • Sign in
  • gmsh gmsh
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 379
    • Issues 379
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 6
    • Merge requests 6
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Releases
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • gmshgmsh
  • gmshgmsh
  • Issues
  • #842
Closed
Open
Issue created Apr 29, 2020 by Martin Řehoř@mrehor

Gmsh changes handler for SIGINT in Python

Gmsh may change the default handler for SIGINT installed by Python to a different one, while this change is not being reverted at the end of using the Gmsh API. This may prevent a program which imports gmsh from catching the standard KeyboardInterrupt exception as demonstrated by the MWE below.

Suggested solution

Replace line 27 in gmsh.py with

ORIGINAL_SIGINT_HANDLER = signal.signal(signal.SIGINT, signal.SIG_DFL)

and call signal.signal(signal.SIGINT, ORIGINAL_SIGINT_HANDLER) within finalize().

MWE

import gmsh
gmsh.initialize()
# ... some gmsh actions
gmsh.finalize()

import time
print("Hit Ctrl+C within 10s to catch 'KeyboardInterrupt' exception...")
try:
    time.sleep(10)
except KeyboardInterrupt:
    print("\nException has been caught")
else:
    print("Exception has not been raised")
finally:
    print("Program has finished properly")

Output (Gmsh 4.5.2, Python 3.6.9, Ubuntu 18.04.4 LTS):

Hit Ctrl+C within 10 seconds to catch 'KeyboardInterrupt' exception...
^C

Expected output (remove gmsh-related block of code to reproduce this):

Hit Ctrl+C within 10 seconds to catch 'KeyboardInterrupt' exception...
^C
Exception has been caught
Program has finished properly
Assignee
Assign to
Time tracking