7
votes
4answers
2k views

How to run one last function before getting killed in Python?

Is there any way to run one last command before a running Python script is stopped by being killed by some other script, keyboard interrupt etc. Thanks for your help!
5
votes
1answer
2k views

Catching / blocking SIGINT during system call

I've written a web crawler that I'd like to be able to stop via the keyboard. I don't want the program to die when I interrupt it; it needs to flush its data to disk first. I also don't want to ...
5
votes
2answers
2k views

Python Multiprocessing atexit Error “Error in atexit._run_exitfuncs”

I am trying to run a simple multiple processes application in Python. The main thread spawns 1 to N processes and waits until they all done processing. The processes each run an infinite loop, so they ...
3
votes
4answers
2k views

Handling Signals in Python Threads

I have a threaded application written in Python, and whenever an interrupt is received via Ctrl+C or sometimes with kill, the application will hang. A stack trace is presented from one thread, but the ...
3
votes
1answer
92 views

Exiting Python interpreter without running garbage collection

At the end of my program, where nothing really needs to happen, the CPython 3.2 interpreter spends almost 2 minutes doing garbage collection. It is a known issue. Luckily, in my case, I don't need to ...
3
votes
5answers
850 views

Capturing user input at arbitrary times in python

Is there a way to send an interrupt to a python module when the user inputs something in the console? For example, if I'm running an infinite while loop, i can surround it with a try/except for ...
3
votes
1answer
267 views

How do I pass/catch/respond to Python's KeyboardInterrupt in C++?

I have a simple library written in C++ which I'm creating a Python wrapper for using boost.python. Some functions take a long time to execute (over 30 seconds), and I would like to make it ...
3
votes
1answer
142 views

Interrupting a timer

I'm creating part of a program right now for a personal project and I need some help on one aspect of it. Here is how the program works: User enters the amount of time to run User enters the text - ...
3
votes
2answers
199 views

Interrupting `while loop` with keyboard in Cython

I want to be able to interrupt a long function with cython, using the usual CTRL+C interrupt command. My C++ long function is repeatedly called inside a while loop from Cython code, but I want to be ...
2
votes
2answers
603 views

Python: Stop the socket-receiving-process

I receive data from some device via socket-module. But after some time the device stops sending packages. Then I want to interupt the for-loop. While True doesn't work, because he receives more then ...
2
votes
2answers
242 views

How to send control C to Mac Terminal using python?

I have a python script that needs to send control C to the mac terminal. I've tried sending the plain text "^C" but I get back that the terminal does not recognize the command. (The terminal meaning ...
1
vote
3answers
987 views

How can I override the keyboard interrupt? (Python)

Is there anyway I can make my script execute one of my functions when Ctrl+c is hit when the script is running?
1
vote
1answer
791 views

Stopping a python program

I have a python program that displays battery voltages and temperatures in an electric car. I typically run it from a command line on a Mac by simply using the up arrow to find the command to change ...
1
vote
0answers
128 views

Custom keyboard function key in Linux

i have built a small COM Port device which on every keypress will generate a a key output in the port. key-1 = 0x31 key-2 = 0x31 FunctionKey1 = 0x90 FunctionKey2 = 0x91 so i am trying to update the ...
0
votes
1answer
453 views

Python - react to custom keyboard interrupt

I am writing python chatbot that displays output through console. Every half second it asks server for updates, and responds to message. In the console I can see chat log. This is sufficient in most ...

1 2
15 30 50 per page