signals

Passing arguments django signals - post_save/pre_save

为君一笑 提交于 2019-11-30 06:14:47
I am working on a notification app in Django 1.6 and I want to pass additional arguments to Django signals such as post_save . I tried to use partial from functools but no luck. from functools import partial post_save.connect( receiver=partial(notify, fragment_name="categories_index"), sender=nt.get_model(), dispatch_uid=nt.sender ) notify function has a keyword argument fragment_name which I want to pass as default in my signals. Any suggestions? Daniel Rucci Your attempt with partial isn't working because by default these receivers are connected using a weak reference. According to the

Accessing the user's request in a post_save signal

余生颓废 提交于 2019-11-30 06:05:50
I have done the below post_save signal in my project. from django.db.models.signals import post_save from django.contrib.auth.models import User # CORE - SIGNALS # Core Signals will operate based on post def after_save_handler_attr_audit_obj(sender, **kwargs): print User.get_profile() if hasattr(kwargs['instance'], 'audit_obj'): if kwargs['created']: kwargs['instance'].audit_obj.create(operation="INSERT", operation_by=**USER.ID**).save() else: kwargs['instance'].audit_obj.create(operation="UPDATE").save() # Connect the handler with the post save signal - Django 1.2 post_save.connect(after_save

How to trap a SIGNAL in a java application initialized using a bash script

冷暖自知 提交于 2019-11-30 05:17:41
I am catching an INT signal in java using the following code: Signal.handle(new Signal("INT"), new SignalHandler () { public void handle(Signal sig) { log.warn("Received SIGINT signal. Will teardown."); task.tearDown(); // Force exit anyway System.exit(1); } }); When I am using java -jar file.jar to start my application I can catch the signal sent with with kill -INT PID . If I call java -jar file.jar & (jvm runs in the background), I can't catch the signal sent with kill -INT . Any ideas? Thanks. Works for me. Are you sure you are killing the right pid? On Unix you can use $! to get the pid

How to debug programs using signals?

久未见 提交于 2019-11-30 05:09:17
#include <stdio.h> #include <signal.h> static volatile sig_atomic_t being_debugged = 1; static void int3_handler(int signo) { being_debugged = 0; } int main() { signal(SIGTRAP, int3_handler); __asm__ __volatile__("int3"); if (being_debugged) { puts("No, I don't want to serve you."); while (1) { /* endless loop */ ; } } puts("Yes, real routines go here."); return 0; } The above will give different output when run inside/outside gdb,because gdb captures the sigtrap signal. How to make my program behaves the same in gdb? GDB will stop the inferior (being debugged) program when the inferior

Time out decorator on a multprocessing function

孤街浪徒 提交于 2019-11-30 05:09:15
问题 I have this decorator taken directly from an example I found on the net: class TimedOutExc(Exception): pass def timeout(timeout): def decorate(f): def handler(signum, frame): raise TimedOutExc() def new_f(*args, **kwargs): old = signal.signal(signal.SIGALRM, handler) signal.alarm(timeout) try: result = f(*args, **kwargs) except TimedOutExc: return None finally: signal.signal(signal.SIGALRM, old) signal.alarm(0) return result new_f.func_name = f.func_name return new_f return decorate It throws

Unix pthreads and signals: per thread signal handlers

心不动则不痛 提交于 2019-11-30 05:04:54
I'm having trouble getting threads to catch the correct signals. For example, I first start a main thread (tid 1). Then, it sets a signal handler for SIGUSR1 to function1(), using signal(2) . The main thread creates a new thread, with tid 2. In thread 2, I register a signal handler for SIGUSR1 to function2() using signal(2) . Thread 1 then creates a thread 3 (tid 3). From thread 3, I use pthread_kill(1, SIGUSR1) to send a signal to thread 1. However, function2() gets called, not function1() . Is this behavior intended, or is there something I need to change to get these signal handlers to work

What are the differences between event and signal in Qt

妖精的绣舞 提交于 2019-11-30 04:48:42
It is hard for me to understand the difference between signals and events in Qt, could someone explain? An event is a message encapsulated in a class ( QEvent ) which is processed in an event loop and dispatched to a recipient that can either accept the message or pass it along to others to process. They are usually created in response to external system events like mouse clicks. Signals and Slots are a convenient way for QObject s to communicate with one another and are more similar to callback functions . In most circumstances, when a "signal" is emitted, any slot function connected to it is

Is it possible to signal handler to survive after “exec”?

这一生的挚爱 提交于 2019-11-30 04:29:39
I wrote a signal handler for a process, and fork() after that, the signal handler will be applied to both parent and child processes. If I replace the child process with "exec", the signal handler is no more. I know this happens because "exec" call will overwrite the child process address space with it's own. I just want to know if there is a way to make signal handler work even after "exec" call ? No. From the man pages: execve() does not return on success, and the text, data, bss, and stack of the calling process are overwritten by that of the program loaded. The program invoked inherits the

catching signals while reading from pipe with select()

♀尐吖头ヾ 提交于 2019-11-30 04:05:51
using select() with pipe - this is what I am doing and now I need to catch SIGTERM on that. how can I do it? Do I have to do it when select() returns error ( < 0 ) ? First, SIGTERM will kill your process if not caught, and select() will not return. Thus, you must install a signal handler for SIGTERM . Do that using sigaction() . However, the SIGTERM signal can arrive at a moment where your thread is not blocked at select() . It would be a rare condition, if your process is mostly sleeping on the file descriptors, but it can otherwise happen. This means that either your signal handler must do

standard way to perform a clean shutdown with Boost.Asio

∥☆過路亽.° 提交于 2019-11-30 02:36:25
I'm writing a cross-platform server program in C++ using Boost.Asio. Following the HTTP Server example on this page, I'd like to handle a user termination request without using implementation-specific APIs. I've initially attempted to use the standard C signal library, but have been unable to find a design pattern suitable for Asio. The Windows example's design seems to resemble the signal library closest, but there's a race condition where the console ctrl handler could be called after the server object has been destroyed. I'm trying to avoid undefined behavior as specified by the C++