signals

PySide / Qt : Too many arguments to connect a signal to a slot?

PySide / Qt : Too many arguments to connect a signal to a slot? Question: I’m trying to connect a custom signal (in a TCP client class) to a method that updates a log with the data sent by the server and whatnot. Here’s the declaration of the TCP client class: class CarSocket(QObject): logSignal = …

Total answers: 3

Can I raise a signal from python?

Can I raise a signal from python? Question: The topic basically tells what I want to to. I read the documentation, which tells me how to handle signals but not how I can do signalling by myself. Thanks! Asked By: Simbi || Source Answers: Use os.kill. For example, to send SIGUSR1 to your own process, …

Total answers: 4

Making sure a Python script with subprocesses dies on SIGINT

Making sure a Python script with subprocesses dies on SIGINT Question: I’ve got a command that I’m wrapping in script and spawning from a Python script using subprocess.Popen. I’m trying to make sure it dies if the user issues a SIGINT. I could figure out if the process was interrupted in a least two ways: …

Total answers: 5

How do I mock a django signal handler?

How do I mock a django signal handler? Question: I have a signal_handler connected through a decorator, something like this very simple one: @receiver(post_save, sender=User, dispatch_uid=’myfile.signal_handler_post_save_user’) def signal_handler_post_save_user(sender, *args, **kwargs): # do stuff What I want to do is to mock it with the mock library http://www.voidspace.org.uk/python/mock/ in a test, to check how many times …

Total answers: 7

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

Catch Ctrl+C / SIGINT and exit multiprocesses gracefully in python Question: 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, …

Total answers: 3

python: windows equivalent of SIGALRM

python: windows equivalent of SIGALRM Question: I have this decorator: def timed_out(timeout): def decorate(f): if not hasattr(signal, “SIGALRM”): return f def handler(signum, frame): raise TimedOutExc() @functools.wraps(f) def new_f(*args, **kwargs): old = signal.signal(signal.SIGALRM, handler) signal.alarm(timeout) try: result = f(*args, **kwargs) finally: signal.signal(signal.SIGALRM, old) signal.alarm(0) return result new_f.func_name = f.func_name return new_f return decorate The code only …

Total answers: 3

Any workarounds for Python's select and handling of EINTR in Linux?

Any workarounds for Python's select and handling of EINTR in Linux? Question: In one of my recent projects I happened to have in the same process (a Python program, its a multithreaded application): a Boost::Python module to a library that linked against the AVT PvAPI SDK, i.e. in the widest sense a driver to get …

Total answers: 2

How can I override the keyboard interrupt? (Python)

How can I override the keyboard interrupt? (Python) Question: Is there anyway I can make my script execute one of my functions when Ctrl+c is hit when the script is running? Asked By: Takkun || Source Answers: Take a look at signal handlers. CTRL-C corresponds to SIGINT (signal #2 on posix systems). Example: #!/usr/bin/env python …

Total answers: 3

Python – How are signals different from pubsub?

Python – How are signals different from pubsub? Question: Django and Flask make use of signals — the latter uses the Blinker library. In the context of Python, Blinker and the Python pubsub library, how do signals and pubsub compare? When would I use one or the other? Asked By: a paid nerd || Source …

Total answers: 2

Python: How to prevent subprocesses from receiving CTRL-C / Control-C / SIGINT

Python: How to prevent subprocesses from receiving CTRL-C / Control-C / SIGINT Question: I am currently working on a wrapper for a dedicated server running in the shell. The wrapper spawns the server process via subprocess and observes and reacts to its output. The dedicated server must be explicitly given a command to shut down …

Total answers: 5