signals

run code after transaction commit in Django

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 17:57:46
Is there any way to run some code after transaction commit in Django? I need to send some messages to a rabbitmq server for offline processing, but the message gets to the consumer before the Django transaction is commited. My message is sent in the post_save signal of the model. What I'm looking for is a similar mechanism, using signals or something else, that would execute code after the commit (and do nothing if the transaction fails). I haven't found any generic way of doing it in Django. Do you have any ideas? UPDATE 2 : django-transaction-hooks was merged into Django core and released in

How do unix signals work?

坚强是说给别人听的谎言 提交于 2019-11-28 17:37:22
How do signals work in unix? I went through W.R. Stevens but was unable to understand. Please help me. The explanation below is not exact, and several aspects of how this works differ between different systems (and maybe even the same OS on different hardware for some portions), but I think that it is generally good enough for you to satisfy your curiosity enough to use them. Most people start using signals in programming without even this level of understanding, but before I got comfortable using them I wanted to understand them. signal delivery The OS kernel has a data structure called a

Python: How to prevent subprocesses from receiving CTRL-C / Control-C / SIGINT

独自空忆成欢 提交于 2019-11-28 16:40:09
I am currently working on a wrapper for a dedicated server running in the shell. The wrapper spawns the server process via subprocess and observes and reacts to its output. The dedicated server must be explicitly given a command to shut down gracefully. Thus, CTRL-C must not reach the server process. If I capture the KeyboardInterrupt exception or overwrite the SIGINT-handler in python, the server process still receives the CTRL-C and stops immediately. So my question is: How to prevent subprocesses from receiving CTRL-C / Control-C / SIGINT? robert Somebody in the #python IRC-Channel

How to trigger SIGUSR1 and SIGUSR2?

蓝咒 提交于 2019-11-28 16:27:16
问题 I'm getting acquainted with signals in C. I can't figure out what kind of signals SIGUSR1 and SIGUSR2 are and how can I trigger them. Can anyone please explain it to me? 回答1: They are user-defined signals, so they aren't triggered by any particular action. You can explicitly send them programmatically: #include <signal.h> kill(pid, SIGUSR1); where pid is the process id of the receiving process. At the receiving end, you can register a signal handler for them: #include <signal.h> void my

PyQt4.QtCore.pyqtSignal object has no attribute 'connect'

浪子不回头ぞ 提交于 2019-11-28 16:14:02
问题 I'm having issues with a custom signal in a class I made. Relevant code: self.parse_triggered = QtCore.pyqtSignal() def parseFile(self): self.emit(self.parse_triggered) Both of those belong to the class: RefreshWidget. In its parent class I have: self.refreshWidget.parse_triggered.connect(self.tabWidget.giveTabsData()) When I try to run the program, I get the error: AttributeError: 'PyQt4.QtCore.pyqtSignal' object has no attribute 'connect' Help? Thanks in advance. 回答1: I had the same exact

Why can't Unix programs have signals with meaningful program defined names (rather than USR1, etc)?

浪子不回头ぞ 提交于 2019-11-28 14:53:40
问题 Many Unix programs accept signals like USR1 and USR2 . For example, to upgrade the executable for Nginx on the fly, you send kill -USR2 . I understand that USR1 is a "user defined" signal, meaning that whoever created the program can use it to mean "shut down" or "dump your logs" or "print foo a thousand times" or whatever. But I don't understand why they must use this arbitrary name. Why not kill -UPGRADE , or kill -GRACEFUL_SHUTDOWN ? Does Unix only allow specific signals? While we're at it

Why doesn't my signal handler (which throws an exception) trigger more than once?

こ雲淡風輕ζ 提交于 2019-11-28 14:19:11
I am trying to set up an exception handler using sigaction. It works well for the first exception. But the sigaction handler is not called after the 1st exception and the program ends abruptly when the second signal happens. #include <iostream> #include <signal.h> #include <exception> #include <string.h> typedef void (*SigactionHandlerPointer)(int iSignal, siginfo_t * psSiginfo, void * psContext); using namespace std; void SigactionHookHandler( int iSignal, siginfo_t * psSiginfo, void * psContext ) { cout << "Signal Handler Exception Caught: std::exception -- signal : " << iSignal << " from

How do I configure ruby to enter the debugger on Ctrl-C (SIGINT)?

青春壹個敷衍的年華 提交于 2019-11-28 14:06:16
I'd like to enter the debugger upon typing ctrl-C (or sending a SIGINT). I have installed the debugger (I'm running Ruby 1.9.3) and verified that it works. I've added this to my setup files (this is for Padrino, but I assume it would be similar for Rails): # file: config/boot.rb Padrino.before_load do trap("SIGINT") { debugger } if Padrino.env == :development end ... but typing Ctrl-C does not invoke the debugger. In fact, if I replace debugger with puts "saw an interrupt!" , typing Ctrl-C doesn't cause a print to happen either. update Following this suggestion from Mike Dunlavey , I tried

SIGIO arriving for file descriptors I did not set it for and when no IO is possible

时光毁灭记忆、已成空白 提交于 2019-11-28 13:52:27
I am trying to receive a signal when I/O is possible on a file descriptor. The program needs to be doing something else when it is not doing I/O, so using select(2) is not an option. When I run the sample code is below, it is printing the message from inside the handler as fast as it can, even when there is no data on stdin. Even weirder is that the file descriptor reported in the siginfo_t structure varies from run to run. I only set it up for stdin (fd 0); why would the handler report any other value? Sometimes I see 0, sometimes, I see 1, most of the time I see '?', which indicates a value

Why no output on console on signal handling?

纵然是瞬间 提交于 2019-11-28 13:47:45
I was trying this program from Advance Programming in Unix Environment. #include<stdio.h> #include<signal.h> static void handler(int sig){ if(sig == SIGUSR1) printf("handled user1 signal"); else if(sig == SIGUSR2) printf("handles user2 signal"); else printf("unkown signal"); } int main(){ if(signal(SIGUSR1, handler) == SIG_ERR) printf("can't handle signal SIGUSR1"); if(signal(SIGUSR2, handler) == SIG_ERR) printf("can't handle signal SIGUSR2"); for(;;) pause(); return 0; } I am using Ubuntu 11.10. I compile the program with gcc and then run a.out as indicated in the book. $./a.out& [1]+ 1345 $