signals

Django: m2m_changed not fired when end of relation is deleted

岁酱吖の 提交于 2019-12-12 22:02:38
问题 NOTICE : due to production environment constraints, I must stick to django-1.4 for the moment. I've just made a test to see whether I can hook onto an event when ManyToMany changes. I have a Group model that holds several Item objects. Whenever the items change in any group, I want to do something with concerned Group` instances. from django.db import models from django.db.models.signals import m2m_changed, post_delete, pre_delete class Item(models.Model): name = models.CharField(max_length

How to use pipes and signals correctly at the same time?

喜夏-厌秋 提交于 2019-12-12 21:13:08
问题 I have 2 children, and I want to send signals from children to parent, and an answer (random number, why? why not...) named pipe from the parent to each child. I have this code: #include <stdlib.h> #include <stdio.h> #include <signal.h> #include <sys/types.h> #include <time.h> #include <unistd.h> #include <sys/wait.h> #include <sys/stat.h> #include <fcntl.h> #include <errno.h> #include <unistd.h> #include <string.h> #define WRITE(Str) (void)write(1,Str,strlen(Str)) void handler(int signumber)

What is the actual signal behind ERR

落花浮王杯 提交于 2019-12-12 18:28:13
问题 I've read in several places (including SO) that -e is considered "poor form" and is unreliable for exiting a script on any error. A better way to handle errors seems to be using trap , as such: trap "echo there was an error; exit 1;" ERR I can't seem to locate in the man pages what signal ERR is actually? I'm assuming it's SIGQUIT but I can't find for sure. man 7 signal only has the normal signals you would expect SIGTERM SIGQUIT SIGINT , etc. man trap has references to ERR signal, but doesn

Django signal get request full path

拥有回忆 提交于 2019-12-12 17:16:59
问题 I wrote a signal in my django project, inside I want to send an email with the full path of my website. But to do so, I need to get the request object inside the signal, how could I do that? Thanks. @receiver(pre_save, sender=AccessRequest) def email_if_access_true(sender, instance, **kwargs): #How can I get the full path of my website here? pass 回答1: Put following code in your pre_save signal receiver: from django.contrib.sites.models import get_current_site current_site = get_current_site

How to send a signal to the main thread in python without using join?

醉酒当歌 提交于 2019-12-12 15:28:40
问题 I Am trying to send a signal from a child thread to the main thread in a multi-threaded program (cannot use multi-processes). Unfortunately even after exhausting all the reading materials available online (which I could find), I Am unable to get a clear idea of how to do so. I Am a beginner to signals AND to python so please bear with me and explain as you would to a novice. I cannot use the join method in the process, since I want both the threads to be running simultaneously. Here is the

Cleaning up children processes asynchronously

不羁的心 提交于 2019-12-12 15:09:06
问题 This is an example from <Advanced Linux Programming>, chapter 3.4.4. The programs fork() and exec() a child process. Instead of waiting for the termination of the process, I want the parent process to clean up the children process (otherwise the children process will become a zombie process) asynchronously. The can be done using the signal SIGCHLD. By setting up the signal_handler we can make the clean-up work done when the child process ends. And the code the following: #include <stdio.h>

SIGNAL & SLOT macros in Qt : what do they do?

我们两清 提交于 2019-12-12 14:04:45
问题 I'm a beginner in Qt and trying to understand the SIGNAL and SLOT macros. When I'm learning to use the connect method to bind the signal and slot, I found the tutorials on Qt's official reference page uses: connect(obj1, SIGNAL(signal(int)), obj2, SLOT(slot())) However, this also works very well: connect(obj1, &Obj1::signal, obj2, &Obj2::slot) So what exactly do the macros SIGNAL and SLOT do? Do they just look for the signal in the class the object belongs to and return the address of it?

POSIX timer runs at twice the expected frequency

纵然是瞬间 提交于 2019-12-12 13:52:17
问题 In order to create a high accuracy timer, I have written a module that instantiates a POSIX timer using the timer_create() function. It uses CLOCK_REALTIME as its clock kind, SIGEV_SIGNAL as notification method and SIGRTMIN as the signal number. Its signal handler does nothing but a sem_post(). The timer is started using timer_settime(), with any number of milliseconds as the timer interval. The user of the module can wait for a timer-tick; the wait functionality is essentially implemented by

Using sleep and select with signals

故事扮演 提交于 2019-12-12 13:35:10
问题 I want to use the select() function to wait for 1 second, as my program uses signals to control stuff, so sleep() would return prematurely. The weird thing is that when using select() it also returns prematurely. I am calling select like this struct timeval timeout; timeout.tv_sec = 10; timeout.tv_usec = 1000000; select (0 ,NULL, NULL, NULL, &timeout); but whenever a signal arrives, it returns (I am using a nano second timer for the signal) Anyone knows why? 回答1: Try something like this:

C++: Continue execution after SIGINT

喜你入骨 提交于 2019-12-12 13:33:23
问题 Okay, I am writing a program that is doing some pretty heavy analysis and I would like to be able to stop it quickly. I added signal(SIGINT, terminate); to the beginning of main and defined terminate like: void terminate(int param){ cout << endl << endl << "Exit [N]ow, or [A]fter this url?" << endl; std::string answer; cin >> answer; if(answer[0] == 'n' || answer[0] == 'N'){ terminateParser(); exit(1); }else if(answer[0] == 'a' || answer[0] == 'A'){ quitAfterUrl = true; } } In linux, this