signals

Django: save multiple object signal once

…衆ロ難τιáo~ 提交于 2019-12-04 16:39:59
I need some help with sending email when an order is placed. To illustrate the problem, following is the abstract code: class Order(models.Model): user = models.ForeignKey(User) class OrderItem(modes.Model): order = models.ForeignKey(Order, related_name='items') item = models.CharField(max_length=255) unit_price = models.DecimalField() qty = models.IntegerField() item_amount = models.DecimalField() def email_order_on_save(sender, instance, **kwargs): # Need order.items.all() here pass post_save.connect(email_order_on_save, sender=Order) Most of the problems on SO and google seem to deal with

Using Auto and Lambda to handle Signal?

僤鯓⒐⒋嵵緔 提交于 2019-12-04 16:29:57
问题 I have written this program that has a main function, inside which, I am creating two sockets, like this: int sockfd1 = socket(AF_INET, SOCK_STREAM, 0); int sockfd2 = socket(AF_INET, SOCK_STREAM, 0); Now I do some stuff with them, and when the user presses Ctrl+C to terminate the process, I want to make sure the sockets close properly, so I do this: auto sigTermHandler = [&] (int param) { close(sockfd1); close(sockfd2); }; signal(SIGTERM, sigTermHandler); But this throws the following

When is POSIX thread cancellation not immediate?

删除回忆录丶 提交于 2019-12-04 16:14:24
The POSIX specifies two types for thread cancellation type: PTHREAD_CANCEL_ASYNCHRONOUS , and PTHREAD_CANCEL_DEFERRED (set by pthread_setcanceltype(3) ) determining when pthread_cancel(3) should take effect. By my reading, the POSIX manual pages do not say much about these, but Linux manual page says the following about PTHREAD_CANCEL_ASYNCHRONOUS : The thread can be canceled at any time. (Typically, it will be canceled immediately upon receiving a cancellation request, but the system doesn't guarantee this.) I am curious about the meaning about the system doesn't guarantee this . I can easily

How to write Ctrl-C handler in Haskell?

杀马特。学长 韩版系。学妹 提交于 2019-12-04 16:03:26
问题 I tried the following approach: import System.Exit import System.Posix.Signals import Control.Concurrent (threadDelay) main :: IO () main = do installHandler keyboardSignal (Catch (do exitSuccess)) Nothing threadDelay (1000000000) But it only outputs: ^CTest.hs: ExitSuccess on Ctrl-C , instead of exiting. How should I do it properly? 回答1: From the docs of installHandler : a handler is installed which will invoke action in a new thread when (or shortly after) the signal is received. and

Issue with timer with long signal handler (SIGALARM)

夙愿已清 提交于 2019-12-04 13:04:21
There is a timer which sends out signal SIGALARM every 1 sec. A signal handler which sleeps 2 sec is registered. What happens? Specifically, I have following code, in which the process runs multiple threads. It's quite interesting that with this long signal handler, it looks other threads are blocked from execution... Can anyone explain why this is the case? #include <unistd.h> #include <stdio.h> #include <stdlib.h> //rand #include <sys/wait.h> #include <time.h> #include <sys/time.h> #include <pthread.h> #define NUM_THREADS 2 int init_timer(int real_time, int msec) { struct itimerval timeslice

Trying to single step through program with trap-flag and trap-signal-handler, crash on vsyscall

谁说我不能喝 提交于 2019-12-04 12:46:47
I'd like to create a complete instruction trace of the execution of a program, to collect some stats etc. I first tried using linux' ptrace functionality to step through a program (using the tutorial here ). This creates two processes, the traced one and the debugger, and they communicate via signals. I only got around 16K instructions per second (on 1.6GHz Atom), so this is too slow for anything non-trivial. I thought the interprocess communication via signals is too slow, so I tried setting up the debugging in the same process as the execution: Set the trap flag, and create a signal handler.

python 2.6.x theading / signals /atexit fail on some versions?

偶尔善良 提交于 2019-12-04 12:26:23
问题 I've seen a lot of questions related to this... but my code works on python 2.6.2 and fails to work on python 2.6.5. Am I wrong in thinking that the whole atexit "functions registered via this module are not called when the program is killed by a signal" thing shouldn't count here because I'm catching the signal and then exiting cleanly? What's going on here? Whats the proper way to do this? import atexit, sys, signal, time, threading terminate = False threads = [] def test_loop(): while True

Gunicorn exits because https request from Django fails in OpenSSL

和自甴很熟 提交于 2019-12-04 12:24:30
Here's the scenario. I have a Django app being served by Gunicorn on Linux. On certain requests it makes an https call to an external API via httplib2.request() . Sometimes that call fails in such a way that hoses OpenSSL (not sure how, but it's not my fault and doesn't really matter). OpenSSL sends a SIGABRT signal to gunicorn in this case. Gunicorn handles the SIGABRT and promptly system exits (as it should). The root issue as I see it is that OpenSSL asynchronously signals the parent process to abort, rather than returning an error code. Don't tell me to abort because of YOUR personal

How can I handle interrupt signal and call destructor in c++? [duplicate]

喜夏-厌秋 提交于 2019-12-04 12:01:32
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Is destructor called if SIGINT or SIGSTP issued? My code like this: #include <iostream> #include <signal.h> #include <cstdlib> void handler(int) { std::cout << "will exit..." << std::endl; exit(0); } class A { public: A() {std::cout << "constructor" << std::endl;} ~A() {std::cout << "destructor" << std::endl;} }; int main(void) { signal(SIGINT, &handler); A a; for (;;); return 0; } When I pressed Ctrl-C, it

Signal sent to both child and parent process

假装没事ソ 提交于 2019-12-04 11:44:01
As far as I understand signals sent to a parent process should not be sent to children. So why does SIGINT reach both the child and the parent in the example below? #include <stdio.h> #include <signal.h> #include <stdlib.h> #include <unistd.h> void sigCatcher( int ); int main ( void ) { if (signal(SIGINT, sigCatcher) == SIG_ERR) { fprintf(stderr, "Couldn't register signal handler\n"); exit(1); } if(fork() == 0) { char *argv[] = {"find","/",".",NULL}; execvp("find",argv); } for (;;) { sleep(10); write(STDOUT_FILENO, "W\n",3); } return 0; } void sigCatcher( int theSignal ) { write(STDOUT_FILENO,