Loading [MathJax]/extensions/tex2jax.js
PISM, A Parallel Ice Sheet Model 2.2.2-d6b3a29ca committed by Constantine Khrulev on 2025-03-28
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
pism_python.cc
Go to the documentation of this file.
1// Copyright (C) 2011, 2014, 2015, 2016, 2017, 2023 David Maxwell and Constantine Khroulev
2//
3// This file is part of PISM.
4//
5// PISM is free software; you can redistribute it and/or modify it under the
6// terms of the GNU General Public License as published by the Free Software
7// Foundation; either version 3 of the License, or (at your option) any later
8// version.
9//
10// PISM is distributed in the hope that it will be useful, but WITHOUT ANY
11// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13// details.
14//
15// You should have received a copy of the GNU General Public License
16// along with PISM; if not, write to the Free Software
17// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19#include <signal.h>
20#include <errno.h>
21#include <petscsys.h>
22
23#include "pism/pythonbindings/pism_python.hh"
24#include "pism/util/error_handling.hh"
25
26namespace pism {
27namespace python {
28
29void set_abort_on_sigint(bool abort) {
30 gSIGINT_is_fatal = abort;
31}
32
33SigInstaller::SigInstaller(int sig, void (*new_handler)(int)) {
34 m_old_handler = signal(sig, new_handler);
35 m_sig = sig;
36}
37
39 if (m_old_handler != nullptr) {
40 signal(m_sig, m_old_handler);
41 }
42 m_old_handler = NULL;
43}
44
48
49int gSignalSet = 0;
51
53 int rv = gSignalSet;
54 if (rv != 0) {
55 gSignalSet = 0;
56 }
57 return 0;
58}
59
60void sigint_handler(int sig) {
61 if (sig == SIGINT) {
62 if (gSIGINT_is_fatal) {
63 throw pism::RuntimeError(ErrorLocation(), "caught signal SIGTERM.");
64 }
65
66 PetscPrintf(PETSC_COMM_WORLD, "\nCaught signal SIGTERM, waiting to exit.\n");
67 gSignalSet = SIGINT;
68 }
69}
70
71} // end of namespace python
72} // end of namespace pism
void release()
Restores the signal handler to its previous value.
SigInstaller(int sig, void(*new_handler)(int))
Installs handle new_handler for signal sig.
void sigint_handler(int sig)
void set_abort_on_sigint(bool abort)
bool gSIGINT_is_fatal
int check_signal()