signals

django signals, how to use “instance”

筅森魡賤 提交于 2021-02-04 13:07:23
问题 I am trying to create a system which enables user to upload a zipfile, and then extract it using post_save signal. class Project: .... file_zip=FileField(upload_to='projects/%Y/%m/%d') @receiver(post_save, sender=Project) def unzip_and_process(sender, **kwargs): #project_zip = FieldFile.open(file_zip, mode='rb') file_path = sender.instance.file_zip.path with zipfile.ZipFile(file_path, 'r') as project_zip: project_zip.extractall(re.search('[^\s]+(?=\.zip)', file_path).group(0)) project_zip

django signals, how to use “instance”

纵然是瞬间 提交于 2021-02-04 13:05:23
问题 I am trying to create a system which enables user to upload a zipfile, and then extract it using post_save signal. class Project: .... file_zip=FileField(upload_to='projects/%Y/%m/%d') @receiver(post_save, sender=Project) def unzip_and_process(sender, **kwargs): #project_zip = FieldFile.open(file_zip, mode='rb') file_path = sender.instance.file_zip.path with zipfile.ZipFile(file_path, 'r') as project_zip: project_zip.extractall(re.search('[^\s]+(?=\.zip)', file_path).group(0)) project_zip

Sort django signal's receivers

家住魔仙堡 提交于 2021-01-29 10:46:42
问题 Django calls receiver methods in its own way. Is there any way that we can sort the receivers of Django signal? I didn't find anything related to it in official Django documentation. 回答1: Unless I'm mistaken, there isn't any reason to have more than one receiver for the same signal and sender . It is possible but I don't believe it is the right way to approach it and you will not have explicit control over the calling sequence of each. If, for example, you have a set of duplicate signals

Catching signal from Python child process using GLib

核能气质少年 提交于 2021-01-29 06:27:55
问题 I'm trying to control the way my cursor looks during certain points of my program execution. To be specific, I want it to be a "spinner" when a Python script is executing, and then a standard pointer when it's done executing. Right now, I have a leave-event-notify callback in Glade that changes the spinner when it leaves a certain area, but this is non-ideal since the user might not know to move the cursor and the cursor doesn't accurately represent the state of the program. I have my Python

sigaction : using “void (*sa_sigaction)(int, siginfo_t *, void *);”

筅森魡賤 提交于 2021-01-28 10:01:18
问题 In sigaction manpage it's written : sa_sigaction also specifies the action to be associated with signum . This function receives the signal number as its first argument, a pointer to a siginfo_t as its second argument and a pointer to a ucon- text_t (cast to void* ) as its third argument. So we can pass arguments to the signal handler (throught void* ), but I can't find the way. Is there no way to put it anywhere? Example : struct ping_val { int data1; int data2; }; void ping(int sig, siginfo

How do I hook a django-allauth signal?

情到浓时终转凉″ 提交于 2021-01-28 05:08:24
问题 Signals page for django-allauth: https://django-allauth.readthedocs.io/en/latest/signals.html I am trying to hook the email_verified signal: allauth.account.signals.email_confirmed(request, email_address) And am getting nothing whenever a user confirms their email. Here is my code: from allauth.account.signals import email_confirmed from channels import Group def send_to_user_socket(sender, **kwargs): Group('%s.get-started' % (kwargs['request'].user.username)).send({'text': json.dumps({

Why does POSIX demand that system(3) ignores SIGINT and SIGQUIT?

那年仲夏 提交于 2021-01-28 05:07:24
问题 The POSIX spec says The system() function shall ignore the SIGINT and SIGQUIT signals, and shall block the SIGCHLD signal, while waiting for the command to terminate. If this might cause the application to miss a signal that would have killed it, then the application should examine the return value from system() and take whatever action is appropriate to the application if the command terminated due to receipt of a signal. This means that a program that starts a long-running sub-process will

GTK passing structure to callback function in C

对着背影说爱祢 提交于 2021-01-28 05:01:04
问题 Still new in GTK, now trying to work on event-driven programming and stuck in weird situation: there is no problem to send scalar items to callback function, but then it comes to sending struct to it, still receiving the error with no idea what's wrong. Sample "stub" code is: #include <gtk/gtk.h> #include <stdlib.h> void messageup(); void exiting(); struct data{ char *message; GtkWidget *window; }; int main (int argc, char *argv[]) { GtkBuilder *builder; GtkWidget *window; GtkWidget

bash trap won't ignore signal

淺唱寂寞╮ 提交于 2021-01-23 05:11:24
问题 Please consider this bash-script: #!/bin/bash trap '' INT echo sleep: sleep 5 echo rsync: rsync -a /usr/lib /var/tmp Trying to interrupt sleep with ctrl-c fails, as expected. But rsync is interruptible (the order of sleep & rsync doesn't matter)? Any ideas are welcome! Edit: Found a difference: rsync itself starts 2 child procs (client/server, which produce the 2 error msgs, i assume), and these seem not to inherit the 'ignorance' of its parent. Must dive into bash sources and find out how

bash trap won't ignore signal

左心房为你撑大大i 提交于 2021-01-23 04:57:40
问题 Please consider this bash-script: #!/bin/bash trap '' INT echo sleep: sleep 5 echo rsync: rsync -a /usr/lib /var/tmp Trying to interrupt sleep with ctrl-c fails, as expected. But rsync is interruptible (the order of sleep & rsync doesn't matter)? Any ideas are welcome! Edit: Found a difference: rsync itself starts 2 child procs (client/server, which produce the 2 error msgs, i assume), and these seem not to inherit the 'ignorance' of its parent. Must dive into bash sources and find out how