Caffe2 - C++ API
A deep learning, cross platform ML framework
signal_handler.h
1 
17 #pragma once
18 
19 #if defined(__APPLE__)
20 #define CAFFE2_SUPPORTS_SIGNAL_HANDLER
21 #elif defined(__linux__) && !defined(CAFFE2_DISABLE_SIGNAL_HANDLERS)
22 #define CAFFE2_SUPPORTS_FATAL_SIGNAL_HANDLERS
23 #define CAFFE2_SUPPORTS_SIGNAL_HANDLER
24 #endif
25 
26 namespace caffe2 {
27 
29  public:
30  enum class Action {
31  NONE,
32  STOP
33  };
34 
35  // Contructor. Specify what action to take when a signal is received.
36  SignalHandler(Action SIGINT_action,
37  Action SIGHUP_action);
38  ~SignalHandler();
39 
40  Action CheckForSignals();
41 
42  private:
43  bool GotSIGINT();
44  bool GotSIGHUP();
45  Action SIGINT_action_;
46  Action SIGHUP_action_;
47  unsigned long my_sigint_count_;
48  unsigned long my_sighup_count_;
49 };
50 
51 #if defined(CAFFE2_SUPPORTS_FATAL_SIGNAL_HANDLERS)
52 // This works by setting up certain fatal signal handlers. Previous fatal
53 // signal handlers will still be called when the signal is raised. Defaults
54 // to being off.
55 void setPrintStackTracesOnFatalSignal(bool print);
56 bool printStackTracesOnFatalSignal();
57 #endif // defined(CAFFE2_SUPPORTS_SIGNAL_HANDLER)
58 
59 } // namespace caffe2
Copyright (c) 2016-present, Facebook, Inc.