signals

Is Python variable assignment atomic?

浪子不回头ぞ 提交于 2019-11-27 20:28:37
Let's say I am using a signal handler for handling an interval timer. def _aHandler(signum, _): global SomeGlobalVariable SomeGlobalVariable=True Can I set SomeGlobalVariable without worrying that, in an unlikely scenario that whilst setting SomeGlobalVariable (i.e. the Python VM was executing bytecode to set the variable), that the assignment within the signal handler will break something? (i.e. meta-stable state) Update : I am specifically interested in the case where a "compound assignment" is made outside of the handler. (maybe I am thinking too "low level" and this is all taken care of in

how in BOOST send a signal in a thread and have the corresponding slot executed in another thread?

﹥>﹥吖頭↗ 提交于 2019-11-27 20:16:55
In Qt for instance if you emit a signal in a thread other that the GUI thread, the signal is enqueued and executed later in the GUI thread, is there a way to do that with boost? thanks For an event loop use boost::asio::io_service. You can post tasks inside this object and have another thread execute them, in a thread safe way: struct MyClass { boost::io_service service; void doSomethingOp() const { ... } void doSomething() { service.post(boost::bind(&MyClass::doSomethingOp, this)); } void loop() { service.run(); // processes the tasks } }; boost::signal<void()> mySignal; MyClass myClass;

How can I tell in Linux which process sent my process a signal

走远了吗. 提交于 2019-11-27 19:42:31
I have a java application that got SIG TERM . I want to know the pid of the process that sent this signal. Is that possible? grawity Two Linux-specific methods are SA_SIGINFO and signalfd() , which allows programs to receive very detailed information about signals sent, including the sender's PID. Call sigaction() and pass to it a struct sigaction which has the desired signal handler in sa_sigaction and the SA_SIGINFO flag in sa_flags set. With this flag, your signal handler will receive three arguments, one of which is a siginfo_t structure containing the sender's PID and UID. Call signalfd()

About the delivery of standard signals

丶灬走出姿态 提交于 2019-11-27 18:41:27
问题 By contrast, if multiple instances of a standard signal are delivered while that signal is currently blocked , then only one instance is queued. I think the above description is not so clear and causing ambiguity to me: what if the specific signal is not blocked , will multiple instances of the same signal be queued? Where is the signal queued,a process specific location or a global location? How is the queued signals handled, will it be possible that two signals are being processed at the

Django post save signal getting called twice despite uid

我与影子孤独终老i 提交于 2019-11-27 18:16:04
问题 I have registered my signal with the callback using the @receiver decorator @receiver(post_save, sender=User, dispatch_uid='ARandomUniqueString') def do_callback(sender, **kwargs): I have put the from app.signals import * code in __init__.py and I can see that it gets imported twice and I do not think there is a good way to fix it, possibly happening due to installed apps in settings.py . I cannot understand why despite using dispatch_uid and the modelInstance.save being invoked only once, it

Go: Get signal origin

混江龙づ霸主 提交于 2019-11-27 18:14:48
问题 I'm using Go to launch a couple of scripts and when they have some problems they use the "alert" signal, I know Go can capture those signals but I need to know the PID that originated the Signal. in C to the signal handler is passed a structure to know the pid who originated the signal but in Go looks like is not the case package main import ( "fmt" "os" "os/signal" ) func main() { c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt, os.Kill) s := <-c fmt.Println("Got signal:", s) fmt

Catch Ctrl+C / SIGINT and exit multiprocesses gracefully in python

不问归期 提交于 2019-11-27 17:04:34
How do I catch a Ctrl+C in multiprocess python program and exit all processes gracefully, I need the solution to work both on unix and windows. I've tried the following: import multiprocessing import time import signal import sys jobs = [] def worker(): signal.signal(signal.SIGINT, signal_handler) while(True): time.sleep(1.1234) print "Working..." def signal_handler(signal, frame): print 'You pressed Ctrl+C!' # for p in jobs: # p.terminate() sys.exit(0) if __name__ == "__main__": for i in range(50): p = multiprocessing.Process(target=worker) jobs.append(p) p.start() And it's kind of working,

catching SIGINT in a multithreaded program

旧巷老猫 提交于 2019-11-27 16:52:04
问题 I am writing a multithreaded program where I want to handle a possible Ctrl-C command from the user to terminate execution. As far as I know there is no guarantee that the main thread, which is able to cancel every working thread, will catch the signal. Is it, therefore, necessary to have a different signal handler to the code of the working thread so that anyone will catch the signal if it arrives, or is there another way to do that with having a signal handler only in the main thread's code

Signal handlers and logging in Python

ぐ巨炮叔叔 提交于 2019-11-27 16:22:38
问题 Documentation for logging module says that If you are implementing asynchronous signal handlers using the signal module, you may not be able to use logging from within such handlers. This is because lock implementations in the threading module are not always re-entrant, and so cannot be invoked from such signal handlers. This suggests that one should not make logging calls from the code invoked by the signal handler directly or indirectly. If you do once in a while program will be left is a

How to propagate a signal through a collection of scripts?

我的梦境 提交于 2019-11-27 15:45:38
问题 I have an collection of scripts which are controlled by a main one. I want to trap the signal ctrl + c in the main script and propagate it to the others. The other scripts should trap this signal as well ( from the main script ) and do some clean-up ... I have tried to send kill -s SIGINT to the children, but they seem they are unable to catch the signal( even if trap 'Cleanup' SIGINT being defined on the children scripts ) Any clues how to realize this? 回答1: The following example