signals

signal.alarm not triggering exception on time

♀尐吖头ヾ 提交于 2019-12-05 09:18:46
I've slightly modified the signal example from the official docs (bottom of page). I'm calling sleep 10 but I would like an alarm to be raised after 1 second. When I run the following snippet it takes way more than 1 second to trigger the exception (I think it runs the full 10 seconds). import signal, os def handler(signum, frame): print 'Interrupted', signum raise IOError("Should after 1 second") signal.signal(signal.SIGALRM, handler) signal.alarm(1) os.system('sleep 10') signal.alarm(0) How can I be sure to terminate a function after a timeout in a single-threaded application? jfs From the

Why is signal.SIGALRM not working in Python on windows?

一个人想着一个人 提交于 2019-12-05 09:08:55
I'm trying to understand OS concepts and Python libraries. I came across a specific example mentioned in Python documentation https://docs.python.org/3/library/signal.html link which is not working for me on Windows. import signal, os def handler(signum, frame): print('Signal handler called with signal', signum) raise OSError("Couldn't open device!") # Set the signal handler and a 5-second alarm signal.signal(signal.SIGALRM, handler) signal.alarm(5) # This open() may hang indefinitely fd = os.open('/dev/ttyS0', os.O_RDWR) signal.alarm(0) # Disable the alarm Is there any specific reason why

QML: Using cpp signal in QML always results in “Cannot assign to non-existent property”

浪子不回头ぞ 提交于 2019-12-05 08:55:44
I just want to connect a cpp signal to a qml slot and tried different ways, but it always results in the same QML-Error at runtime: Cannot assign to non-existent property "onProcessed" ! Why? This is my Cpp Object: #include <QObject> class ImageProcessor : public QObject { Q_OBJECT public: explicit ImageProcessor(QObject *parent = 0); signals: void Processed(const QString str); public slots: void processImage(const QString& image); }; ImageProcessor::ImageProcessor(QObject *parent) : QObject(parent) { } void ImageProcessor::processImage(const QString &path) { Processed("test"); } This is my

How do I recover from EXC_BAD_ACCESS?

二次信任 提交于 2019-12-05 08:20:51
I'm intentionally causing an EXC_BAD_ACCESS . By triggering a write to an NSObject in a read-only virtual memory page. Ideally, I'd like to catch EXC_BAD_ACCESS , mark the virtual memory page as read-write and have execution continue as it normally would have. Is this even possible? The code I've written to cause the EXC_BAD_ACCESS is below. WeakTargetObject.h (ARC) @interface WeakTargetObject : NSObject @property (nonatomic, weak) NSObject *target; @end WeakTargetObject.m (ARC) @implementation WeakTargetObject @end main.m (MRR) - (void)main { char *mem = NULL; vm_allocate(mach_task_self(),

addHow to make django post_save signal run only during creation

你说的曾经没有我的故事 提交于 2019-12-05 07:42:27
I'm using django-notifications in my project and I want to notify a particular user whenever a model is created using the signal, but the post_save also runs when a model is being updated how do I prevent this and only make the post_save method run when a model is created. models.py class Card(models.Model): user = models.ForeignKey(User,on_delete=models.CASCADE) title = models.CharField(max_length=100) description = models.TextField(blank=True) list = models.ForeignKey(List, related_name='cards') story_points = models.IntegerField(null=True, blank=True) business_value = models.IntegerField

Which functions are interrupted by signals even with SA_RESTART?

三世轮回 提交于 2019-12-05 05:33:14
Is there any reasonably complete list of which functions in POSIX are interrupted with EINTR when a signal is received or handled, even if there is no signal handler or if the handler was installed with SA_RESTART ? Some examples: select nanosleep etc. tcsetattr is also not restartable, at least in Linux 2.6.18 POSIX says: If the signal-catching function executes a return statement, the behavior of the interrupted function shall be as described individually for that function, except as noted for unsafe functions. So, either you look through all functions individually or filter your man pages

When does a process handle a signal

你离开我真会死。 提交于 2019-12-05 05:21:40
问题 I want to know when does a linux process handles the signal. Assuming that the process has installed the signal handler for a signal, I wanted to know when would the process's normal execution flow be interrupted and signal handler called. According to http://www.tldp.org/LDP/tlk/ipc/ipc.html, the process would handle the signal when it exits from a system call. This would mean that a normal instruction like a = b+c (or its equivalent machine code) would not be interrupted because of signal.

How to avoid the interruption of sleep calls due to a signal in Linux?

柔情痞子 提交于 2019-12-05 04:04:42
I'm using a real time signal in Linux to be notified of the arrival of new data in a serial port. Unfortunately this causes sleep calls to be interrupted when there is signal. Does anybody know of a way to avoid this behavior? I tried using a regular signal (SIGUSR1) but I keep getting the same behavior. From the nanosleep manpage: nanosleep delays the execution of the program for at least the time specified in *req. The function can return earlier if a signal has been delivered to the process. In this case, it returns -1, sets errno to EINTR, and writes the remaining time into the structure

How to really test signal handling in Python?

眉间皱痕 提交于 2019-12-05 03:30:31
My code is simple: def start(): signal(SIGINT, lambda signal, frame: raise SystemExit()) startTCPServer() So I register my application with signal handling of SIGINT , then I start a start a TCP listener. here are my questions: How can I using python code to send a SIGINT signal? How can I test whether if the application receives a signal of SIGINT, it will raise a SystemExit exception? If I run start() in my test, it will block and how can I send a signal to it? Martijn Pieters First of, testing the signal itself is a functional or integration test, not a unit test. See What's the difference

how to handle os.system sigkill signal inside python?

不想你离开。 提交于 2019-12-05 03:30:24
I have a python script where I call a lengthy process from the operating system. After a long while, the process that I call gets terminated by the system by SIGKILL signal. Is it possible to handle this from inside Python like in a try and catch situation? What method should I use to solve this issue. It is very important that this process keeps on running as long as possible without any interruptions. There is no way to handle SIGKILL The signals SIGKILL and SIGSTOP cannot be caught, blocked, or ignored. If you're looking to handle system shutdown gracefully, you should be handling SIGTERM