AliceO2Group / o2tuner

A tool for optimizing routines in ALICE O2
GNU General Public License v3.0
4 stars 2 forks source link

Introduce signal handler #51

Closed benedikt-voelkel closed 1 year ago

benedikt-voelkel commented 1 year ago
benedikt-voelkel commented 1 year ago

Using SIGTSTP now (hence catching Ctrl-Z) to shutdown optimisation. Ctrl-C shuts down, as discussed What do you think @mconcas ?

mconcas commented 1 year ago

Using SIGTSTP now (hence catching Ctrl-Z) to shutdown optimisation. Ctrl-C shuts down, as discussed What do you think @mconcas

Provided that I think we should ultimately follow your taste, what about ^\ (SIGQUIT) instead? I have it on my ubuntu box to be checked if it is also available on macOS iterm2.

mconcas@box$ stty -a | grep intr
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;

One could expect that sending a SIGSTOP leaves the process in a state that can be resumed. Again is common habits vs "just learn that this keys combination is trapped in o2tuner". If signal 3 is unavailable, SIGSTP can also work.

To see if the signal is caught correctly I used this snippet and it was actually getting the ^\ combination.

import signal
import time

def signal_handler(sig, frame):
    print(f"Received signal {sig}")

for sig in (signal.SIGINT, signal.SIGTERM, signal.SIGQUIT):
    signal.signal(sig, signal_handler)

start_time = time.time()
while time.time() - start_time < 10:
benedikt-voelkel commented 1 year ago

Agreed, using SIGQUIT now. So Ctrl-Z would trigger SIGTSTP and might put process into bg as the user might be used to.

Did additional adjustments to avoid flake8 and pylint complaining about methods being too complex --> some modularisation optimise.py (which I think might make sense in any case)