signals

Multiple subprocesses with timeouts

狂风中的少年 提交于 2019-12-04 11:32:51
问题 I'm using a recipe that relies on SIGALRM to set alarm interrupt -- Using module 'subprocess' with timeout The problem is that I have more than one Python script using signal.ALARM process to set time-outs, and only the latest alarm gets called. What is a good way to improve this multiple Python functions setting time-outs? 回答1: Except for simple, quick hacks, avoid SIGALRM. It's a very old, limited mechanism, not suited to anything more complex: you can only set a single alarm, and it

Portable way to catch signals and report problem to the user

岁酱吖の 提交于 2019-12-04 11:27:01
If by some miracle a segfault occurs in our program, I want to catch the SIGSEGV and let the user (possibly a GUI client) know with a single return code that a serious problem has occurred. At the same time I would like to display information on the command line to show which signal was caught. Today our signal handler looks as follows: void catchSignal (int reason) { std :: cerr << "Caught a signal: " << reason << std::endl; exit (1); } I can hear the screams of horror with the above, as I have read from this thread that it is evil to call a non-reentrant function from a signal handler. Is

Using long data inside signal handler.

烂漫一生 提交于 2019-12-04 11:16:34
How can I set a variable of type long (on 64 bit machine = 8 bytes) inside a signal handler? I've read that you can only use variables of type sig_atomic_t , which is actually implemented as volatile int inside a signal handler and it is unsafe to modify data types bigger than an int . You can use a long inside a signal handler, you can use anything, in fact. The only thing you should take care of is proper synchronization in order to avoid race conditions. sig_atomic_t should be used for variables shared between the signal handler and the rest of the code. Any variable "private" to the signal

Wait for signal, then continue execution

旧巷老猫 提交于 2019-12-04 10:51:50
I am trying to make a program that suspends its execution until a signal arrives . Then, after the signal arrives I just want my code to continue its execution from where it was . I don't want it to execute a function handler or whatsoever. Is there a simple way of doing this? I have been struggling for a week or so, reading here and there, and didn't manage to get a fully operative code. In particular, I want the main program to create a thread that waits for some particular event to happen (e.g., a user has input some data to stdin). Meanwhile, the main program is doing something but at some

sigtimedwait() returns EAGAIN before timeout

狂风中的少年 提交于 2019-12-04 10:23:49
I'm trying to learn how to use sigtimedwait(), but I find that it's not waiting for the timeout to complete. Below it seems to return EAGAIN 4s faster than it should (1s faster per 1min of timeout): #include <signal.h> #include <syslog.h> #include <stdarg.h> #include <stddef.h> #include <errno.h> int main(int argc, char* argv[]) { setlogmask(LOG_UPTO(LOG_NOTICE)); openlog ("SIG_TIMED_WAITER", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1); syslog (LOG_NOTICE, "Started"); sigset_t set; sigemptyset(&set); sigaddset(&set, SIGUSR1); struct timespec to; to.tv_sec = 240; to.tv_nsec = 0; int ret =

Performance of signals in Django

好久不见. 提交于 2019-12-04 10:13:29
I have created a few post_save signals but I was wondering if there will be performance issues later on. For example, I have something like this: def my_signal(sender, **kwargs): # some minimal processing posts = len(MyPosts.objects.filter(date__gte=variable)) if entries == "20": # crate an object and assign it to the post's author. post_save.connect(my_signal, sender=MyPosts) Let's say I have a very busy site and this is firing each time a post is created. Is it too bad to performance?. Is there a way to fire signals in a more slow-paced way (maybe, once a day or every few requests)?. UPDATE

where to put django signal receiver code, spread them over multiple files?

我只是一个虾纸丫 提交于 2019-12-04 10:12:14
I've put my signal receiver code in the respective model file. However, signal receivers keep growing and I'd like to separate them over multiple files. I haven't seen discussion on where to put signal receiver codes. (makes me suspect that I'm not supposed to make many signal receivers maybe?) See the docs: https://docs.djangoproject.com/en/1.8/topics/signals/#connecting-receiver-functions it's common to put them in a separate signals.py file, perhaps one per module in your project, but you need to ensure that these files get imported so that your signal receivers get registered. as detailed

Calculate the Fourier series with the trigonometry approach

强颜欢笑 提交于 2019-12-04 09:32:48
问题 I try to implement the Fourier series function according to the following formulas: ...where... ...and... Here is my approach to the problem: import numpy as np import pylab as py # Define "x" range. x = np.linspace(0, 10, 1000) # Define "T", i.e functions' period. T = 2 L = T / 2 # "f(x)" function definition. def f(x): return np.sin(np.pi * 1000 * x) # "a" coefficient calculation. def a(n, L, accuracy = 1000): a, b = -L, L dx = (b - a) / accuracy integration = 0 for i in np.linspace(a, b,

malloc inside linux signal handler cause deadlock

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 09:32:40
First of all sorry for calling malloc inside signal handler :).I too understand we should not do any time consuming task/this kind of nasty stuff inside signal handler. But i am curious to know the reason why it is crashed ? #0 0x00006e3ff2b60dce in _lll_lock_wait_private () from /lib64/libc.so.6 #1 0x00006e3ff2aec138 in _L_lock_9164 () from /lib64/libc.so.6 #2 0x00006e3ff2ae9a32 in malloc () from /lib64/libc.so.6 #3 0x00006e3ff1f691ad in ?? () from .. i got similar core reported in https://access.redhat.com/solutions/48701 . operating system : RHEL P.P. malloc() is not a function that can be

Multithreaded C program; how to kill processes spawned by threads?

走远了吗. 提交于 2019-12-04 09:29:45
Situation: I am writing a program in C that maintains a number of threads. Once a thread ends, a new one is created. Each thread forks - the child runs a process via exec() and the parent waits for it to finish. In addition, there is a signal handler thread that waits for signals. If SIGINT is detected then it tells the main thread to stop creating threads so eventually all the threads end and the program can exit. Signals are blocked in all threads except of course the signal handler thread. Aim: I want to be able to terminate the program by sending SIGTERM. This would work by stopping the