Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally disable pipeline halt on SIGINT #154

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/include/core/G3Pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class G3Pipeline {

// Run the pipeline to completion. If profile is set to true, will print
// statistics for each module at completion.
void Run(bool profile = false, bool graph = false);
void Run(bool profile = false, bool graph = false, bool signal_halt = true);

// If there is stored graph information get it
std::string GetGraphInfo() const {
Expand Down
19 changes: 11 additions & 8 deletions core/src/G3Pipeline.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ G3Pipeline::siginfo_catcher(int)
#endif

void
G3Pipeline::Run(bool profile, bool graph)
G3Pipeline::Run(bool profile, bool graph, bool signal_halt)
{
struct rusage last_rusage;
std::vector<G3Pipeline_mod_data> mods;
Expand All @@ -239,12 +239,14 @@ G3Pipeline::Run(bool profile, bool graph)
getrusage(RUSAGE_THREAD, &last_rusage);
#endif

// Catch SIGINT
sigint_catcher.sa_handler = &G3Pipeline::sigint_catcher;
sigint_catcher.sa_flags = SA_RESTART | SA_RESETHAND;
sigemptyset(&sigint_catcher.sa_mask);
sigaddset(&sigint_catcher.sa_mask, SIGINT);
sigaction(SIGINT, &sigint_catcher, &oldsigint);
if (signal_halt) {
// Catch SIGINT
sigint_catcher.sa_handler = &G3Pipeline::sigint_catcher;
sigint_catcher.sa_flags = SA_RESTART | SA_RESETHAND;
sigemptyset(&sigint_catcher.sa_mask);
sigaddset(&sigint_catcher.sa_mask, SIGINT);
sigaction(SIGINT, &sigint_catcher, &oldsigint);
}

#ifdef SIGINFO
if (profile) {
Expand Down Expand Up @@ -288,7 +290,8 @@ G3Pipeline::Run(bool profile, bool graph)

// Restore old handler
G3Pipeline::halt_processing = false;
sigaction(SIGINT, &oldsigint, &sigint_catcher);
if (signal_halt)
sigaction(SIGINT, &oldsigint, &sigint_catcher);
#ifdef SIGINFO
if (profile)
sigaction(SIGINFO, &oldsiginfo, &siginfo_catcher);
Expand Down
11 changes: 7 additions & 4 deletions core/src/python.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -578,17 +578,20 @@ SPT3G_PYTHON_MODULE(core)
"\t processing if returned by first module. Equivalent to [].\n")
.def("_Add_", &G3Pipeline::Add, bp::arg("name")="")
.def("Run", &G3Pipeline::Run,
(bp::arg("profile")=false, bp::arg("graph")=false),
(bp::arg("profile")=false, bp::arg("graph")=false,
bp::arg("signal_halt")=true),
"Run pipeline. If profile is True, print execution time "
"statistics for each module when complete. If graph is True, "
"stores control flow data that can be processed with GraphViz "
"once retrieved using GetGraphInfo().")
"once retrieved using GetGraphInfo(). If signal_halt is True "
"(default), the pipeline will stop processing new frames when "
"SIGINT is sent to this process. Equivalent to what happens when "
"halt_processing() is called.")
.def("GetGraphInfo", &G3Pipeline::GetGraphInfo,
"Get stored control flow information from Run(graph=True)")
.def("halt_processing", &G3Pipeline_halt_processing,
"Halts all running pipelines after they flush all currently "
"in-flight frames. Equivalent to what happens when SIGINT is "
"sent to this process. Once set, the first module will not be "
"in-flight frames. Once set, the first module will not be "
"called again.")
.staticmethod("halt_processing")
.def_readonly("last_frame",
Expand Down
Loading