signals

Django: signal when user logs in?

不想你离开。 提交于 2019-12-17 07:09:23
问题 In my Django app, I need to start running a few periodic background jobs when a user logs in and stop running them when the user logs out, so I am looking for an elegant way to get notified of a user login/logout query user login status From my perspective, the ideal solution would be a signal sent by each django.contrib.auth.views.login and ... views.logout a method django.contrib.auth.models.User.is_logged_in() , analogous to ... User.is_active() or ... User.is_authenticated() Django 1.1.1

In what order should I send signals to gracefully shutdown processes?

我怕爱的太早我们不能终老 提交于 2019-12-17 03:46:38
问题 In a comment on this answer of another question, the commenter says: don’t use kill -9 unless absolutely necessary! SIGKILL can’t be trapped so the killed program can’t run any shutdown routines to e.g. erase temporary files. First try HUP (1), then INT (2), then QUIT (3) I agree in principle about SIGKILL , but the rest is news to me. Given that the default signal sent by kill is SIGTERM , I would expect it is the most-commonly expected signal for graceful shutdown of an arbitrary process.

Capture SIGINT in Java

对着背影说爱祢 提交于 2019-12-17 03:09:09
问题 What is the best way to capture a kill signal in java without using JNI. I did discover the sun.misc.Signal and the sun.misc.SignalHandler and the warning of the possibility of being removed in the future releases. Would using JNI to call a c lib be the only option i have? 回答1: The way to handle this would be to register a shutdown hook. If you use ( SIGINT ) kill -2 will cause the program to gracefully exit and run the shutdown hooks. Registers a new virtual-machine shutdown hook. The Java

How and why does QuickEdit mode in Command Prompt freeze applications?

浪尽此生 提交于 2019-12-17 02:22:21
问题 I recently ran into an issue with Command Prompt on Windows where QuickEdit mode was enabled and clicking the window was selecting text and hanging a running program. This is, apparently, known behaviour—I found a few questions related to it: Command Line Windows Hanging in RDP Windows Windows Console Application Getting Stuck How to disable QuickEdit Mode for individual scripts How is the application "paused"/"suspended"? Is the process similar to the SIGSTOP signal on *nix? (I am also

Calling pthread_cond_signal without locking mutex

寵の児 提交于 2019-12-17 02:18:31
问题 I read somewhere that we should lock the mutex before calling pthread_cond_signal and unlock the mutext after calling it: The pthread_cond_signal() routine is used to signal (or wake up) another thread which is waiting on the condition variable. It should be called after mutex is locked, and must unlock mutex in order for pthread_cond_wait() routine to complete. My question is: isn't it OK to call pthread_cond_signal or pthread_cond_broadcast methods without locking the mutex? 回答1: If you do

Calling pthread_cond_signal without locking mutex

陌路散爱 提交于 2019-12-17 02:18:20
问题 I read somewhere that we should lock the mutex before calling pthread_cond_signal and unlock the mutext after calling it: The pthread_cond_signal() routine is used to signal (or wake up) another thread which is waiting on the condition variable. It should be called after mutex is locked, and must unlock mutex in order for pthread_cond_wait() routine to complete. My question is: isn't it OK to call pthread_cond_signal or pthread_cond_broadcast methods without locking the mutex? 回答1: If you do

How do I inform a user space application that the driver has received an interrupt in linux?

﹥>﹥吖頭↗ 提交于 2019-12-14 04:19:41
问题 I have a PCIe device that will send a hardware interrupt when a data buffer is ready to be read. I believe the best approach for this is to use signals but I'm not entirely sure how. What I believe I need to do is: Save the PID of the user space application so the driver knows where to send the signal In the interrupt handler of the PCIe device driver, send a signal to the user space application In the User space application implement a signal handler function for processing the signal I'm

Sending “ARROW KEY” key through serial port

一个人想着一个人 提交于 2019-12-14 03:53:36
问题 In the same way that the question Sending “ENTER” key through serial port how can i send the "ARROW key" through the serial port? Most particuly the UP arrow key. 回答1: Cursor keys are a relatively new feature of keyboards. They didn't yet exist at the time the ASCII codes were chosen. Which was largely based on the capabilities of teletypes that were used at that time. Like the widely used ASR-33, its keyboard layout looked like this: No cursor keys. Note how line-feed was a separate key back

Bash, CTRL+C in eval not interrupting the main script

℡╲_俬逩灬. 提交于 2019-12-14 03:46:01
问题 In my bash script, I'm running an external command that's stored in $cmd variable. (It could be anything, even some simple bash oneliner.) If ctrl + C is pressed while running the script, I want it to kill the currently running $cmd but it should still continue running the main script. However, I would like to preserve the option to kill the main script with ctrl + C when the main script is running. #!/bin/bash cmd='read -p "Ooook?" something; echo $something; sleep 4 ' while true; do echo

Thread-Safe Signal API in Python 2.7

狂风中的少年 提交于 2019-12-14 03:37:28
问题 I have a multi-threaded program and want to catch SIGINT. I tried using the signal interface but it appears to stop doing anything when the program uses threading . What is the correct signal API for multi-threaded python programs? import signal import sys import threading import os # register my Ctrl-C handler def signal_handler(signal, frame): print('Signal.') os._exit(0) signal.signal(signal.SIGINT, signal_handler) # stop the main thread lock = threading.Lock() with lock: threading