signals

Stop SIGALRM when function returns

杀马特。学长 韩版系。学妹 提交于 2021-02-20 13:37:51
问题 I have a problem that I can't seem to solve by myself. I'm writing a small python script and I would like to know why my signal.alarm still works after the function it's located in returned. Here is the code: class AlarmException(Exception): pass def alarmHandler(signum, frame): raise AlarmException def startGame(): import signal signal.signal(signal.SIGALRM, alarmHandler) signal.alarm(5) try: # some code... return 1 except AlarmException: # some code... return -1 def main(): printHeader()

Stop SIGALRM when function returns

≯℡__Kan透↙ 提交于 2021-02-20 13:36:10
问题 I have a problem that I can't seem to solve by myself. I'm writing a small python script and I would like to know why my signal.alarm still works after the function it's located in returned. Here is the code: class AlarmException(Exception): pass def alarmHandler(signum, frame): raise AlarmException def startGame(): import signal signal.signal(signal.SIGALRM, alarmHandler) signal.alarm(5) try: # some code... return 1 except AlarmException: # some code... return -1 def main(): printHeader()

Celery - Obtain the Task ID in task_success signal?

*爱你&永不变心* 提交于 2021-02-19 04:33:25
问题 I have an application that implements the task_success signal like this: @signals.task_success.connect def task_success_handler(sender=None,result=None,**kwargs): print("**************************C100") pprint.pprint(sender.name) print("**************************C100") I can obtain the task name. Is there any way to obtain the task_id ? 回答1: As mentioned in documentation, sender is the task object executed. Task object has request attribute which has all the information related to the task.

Python multiprocessing - Capturing signals to restart child processes or shut down parent process

断了今生、忘了曾经 提交于 2021-02-18 10:49:07
问题 I am using the multiprocessing library to spawn two child processes. I would like to ensure that as long as the parent process is alive, if the child processes die (receive a SIGKILL or SIGTERM), that they are restarted automatically. On the other hand, if the parent process receives a SIGTERM/SIGINT, I want it to terminate all child processes then exit. This is how I approached the problem: import sys import time from signal import signal, SIGINT, SIGTERM, SIGQUIT, SIGCHLD, SIG_IGN from

How to get further information on SIGFPE signal?

亡梦爱人 提交于 2021-02-16 20:11:13
问题 This is from The GNU C Library Reference Manual int SIGFPE The SIGFPE signal reports a fatal arithmetic error. This signal actually covers all arithmetic errors, including division by zero and overflow. BSD systems provide the SIGFPE handler with an extra argument that distinguishes various causes of the exception. In order to access this argument, you must define the handler to accept two arguments, which means you must cast it to a one-argument function type in order to establish the

How to get further information on SIGFPE signal?

末鹿安然 提交于 2021-02-16 20:11:07
问题 This is from The GNU C Library Reference Manual int SIGFPE The SIGFPE signal reports a fatal arithmetic error. This signal actually covers all arithmetic errors, including division by zero and overflow. BSD systems provide the SIGFPE handler with an extra argument that distinguishes various causes of the exception. In order to access this argument, you must define the handler to accept two arguments, which means you must cast it to a one-argument function type in order to establish the

How to kill a process and all of its children in C when executing the process by execv()?

流过昼夜 提交于 2021-02-16 20:00:54
问题 I'm trying to implement a timeout -like command on a unix -based operating system as follows: int pid; timer_t timer_id; struct sigevent timer_event; struct itimerspec timer_value; void timeout_signal_handler(int sig_no) { kill(pid, SIGKILL); } int create_timer() { /* implementation */ } int start_timer_oneshot(int interval_ms) { /* implementation */ } int main(int argc, char* argv[]) { int status, pid_return; void *signal_return; if (argc < 2) return EXIT_FAILURE; signal_return = signal

On epoll_pwait, POSIX timers and X11 events. Most of X11 events is either delayed or dropped

十年热恋 提交于 2021-02-11 12:39:20
问题 The setup is below. have a X11 connection file descriptor x11_fd set in non-blocking mode. have a signal file descriptor sig_fd set in non-blocking mode. create a POSIX timer with timer_create add all above in epoll set main_loop: n = epoll_pwait(ep_fd, ep_evs, MAXEVENTS, -1, &mask_sigs) if(fd == sig_fd) do set some signal flags if(fd == x11_fd) do X11 events if(fd == timer_fd or timeout) do some small computations end_main_loop X11 events are processed with while((event = xcb_poll_for_event(

Terminate threads when SIGINT is called - C

谁说胖子不能爱 提交于 2021-02-10 14:51:05
问题 I'm building a generic program written in C-UNIX (using Linux so I don't care about BSD or WIN functions), that creates two threads to handle the communication with a server. void init_threads(int socket_desc) { pthread_t chat_threads[2]; ret = pthread_create(&chat_threads[0], NULL, receiveMessage, (void*)(long)socket_desc); PTHREAD_ERROR_HELPER(ret, "Errore creazione thread ricezione messaggi"); ret = pthread_create(&chat_threads[1], NULL, sendMessage, (void*)(long)socket_desc); PTHREAD

Python parent process is not catching SIGTERM/SIGINT signals when launching subprocess using os.sytem()

亡梦爱人 提交于 2021-02-10 14:38:20
问题 I have two python scripts as below - parent.py import os import signal shutdown = False def sigterm_handler(signum, frame): global shutdown shutdown = True if __name__ == '__main__': signal.signal(signal.SIGTERM, sigterm_handler) signal.signal(signal.SIGINT, sigterm_handler) os.chdir(os.path.dirname(os.path.abspath(__file__))) cmd = 'python child.py' while True: if shutdown == True: break print 'executing %s' % cmd exit_code = os.system(cmd) print 'Exit Code from %s > %s' % (cmd, exit_code)