sigint

Python SIGINT not catched

泪湿孤枕 提交于 2020-01-01 15:38:09
问题 I don't manage to understand why my SIGINT is never catched by the piece of code below. #!/usr/bin/env python from threading import Thread from time import sleep import signal class MyThread(Thread): def __init__(self): Thread.__init__(self) self.running = True def stop(self): self.running = False def run(self): while self.running: for i in range(500): col = i**i print col sleep(0.01) global threads threads = [] for w in range(150): threads.append(MyThread()) def stop(s, f): for t in threads:

Interrupting Python raw_input() in a child thread with ^C/KeyboardInterrupt

≯℡__Kan透↙ 提交于 2019-12-30 18:29:50
问题 In a multithreaded Python program, one thread sometimes asks for console input using the built-in raw_input(). I'd like to be able to be able to close the program while at a raw_input prompt by typing ^C at the shell (i.e., with a SIGINT signal). However, when the child thread is executing raw_input, typing ^C does nothing -- the KeyboardInterrupt is not raised until I hit return (leaving raw_input). For example, in the following program: import threading class T(threading.Thread): def run

How function signal() works in C with SIGINT

大城市里の小女人 提交于 2019-12-25 01:44:25
问题 #include <stdio.h> #include <signal.h> void f( int ); int main () { int i ; signal ( SIGINT , f) ; for (i =0; i <5; i ++) { printf ( " hello \n " ) ; sleep (10) ; } } void f( int signum ){ //signal ( SIGINT , f) ; printf ( " OUCH !\n ") ; } I am try to learn handle signals in c. In code above i could not understand the way that function signal works. I understand that when i execute this code when i press control-c function f will be executed and would interrupt the loop.But when i press

How function signal() works in C with SIGINT

混江龙づ霸主 提交于 2019-12-25 01:29:29
问题 #include <stdio.h> #include <signal.h> void f( int ); int main () { int i ; signal ( SIGINT , f) ; for (i =0; i <5; i ++) { printf ( " hello \n " ) ; sleep (10) ; } } void f( int signum ){ //signal ( SIGINT , f) ; printf ( " OUCH !\n ") ; } I am try to learn handle signals in c. In code above i could not understand the way that function signal works. I understand that when i execute this code when i press control-c function f will be executed and would interrupt the loop.But when i press

What is the Signal function (SIGINT)?

只愿长相守 提交于 2019-12-23 09:19:30
问题 What does this statement below do? If anyone can explain this function I would really appreciate it. signal(SIGINT, SIG_DFL); 回答1: Set the handling of the SIGINT signal to its default. If you are on a *nix system, try man signal to get answers like this. That (and maybe checking some of the pages listed under "See Also") will also tell you what signals are. As for what the defaults are - it's going to be one of "ignore it", "terminate the program", or "cause the program to dump core". Which

Thin doesn't respond to SIGINT or SIGTERM

╄→гoц情女王★ 提交于 2019-12-22 06:59:57
问题 bundle exec thin start -p 3111 gives the following output: Using rack adapter Thin web server (v1.2.11 codename Bat-Shit Crazy) Maximum connections set to 1024 Listening on 0.0.0.0:3111, CTRL+C to stop ^C Ctrl-C doesn't do anything (SIGINT). Neither does kill (SIGTERM). I've found a few references to this behavior, but no solutions. The problem seems to be either in eventmachine (bundled with latest thin), in ruby 1.9.2-r290, or in the linux kernel (Ubuntu 10.4 LTS, 2.6.38.3-linode32). It

Trap signal in child background process

淺唱寂寞╮ 提交于 2019-12-20 19:41:57
问题 I am unable to trap a signal when running in a child / background process. Here is my simple bash script : #!/bin/bash echo "in child" trap "got_signal" SIGINT function got_signal { echo "trapped" exit 0 } while [ true ]; do sleep 2 done When running this and later do kill -SIGINT (pid) Everything works as expected, it prints 'trapped' and exits. Now, if I start the same script from a parent script like this : #!/bin/bash echo "starting the child" ./child.sh & Then the child does not trap the

Sending SIGINT (Ctrl-C) to program running in Eclipse Console

自古美人都是妖i 提交于 2019-12-20 17:43:14
问题 I have setup a run configuration in Eclipse and need to send SIGINT ( Ctrl + C ) to the program. There is cleanup code in the program that runs after SIGINT, so pressing Eclipse's "Terminate" buttons won't work (they send SIGKILL I think). Typing CTRL + C into the Console also doesn't work. How do I send SIGINT to a process running inside an Eclipse Console? (FWIW I am running a Twisted daemon and need Twisted to shutdown correctly, which only occurs on SIGINT) 回答1: If you can determine the

Sending ctrl-c to specific screen session

两盒软妹~` 提交于 2019-12-20 09:47:13
问题 I am designing a script to launch a process inside a named screen session. as_user "screen -p 0 -S **$command** -X eval 'stuff \"wine LFS.exe /cfg=**$command**.cfg\"\015'" So bash myscript.sh start test will create a screen named test and run the test.cfg with the software. Now I want my script to access the specific screen session and do a CTRL + C to stop the running process so i can kill the screen session. Something like this: as_user "screen -p 0 -S **$command** **... kill the process

How can I handle SIGINT in Erlang?

情到浓时终转凉″ 提交于 2019-12-18 19:38:12
问题 I know how to create custom signal handlers in Java, Python, Ruby, Perl, and Lisp, thanks to Google and a plethora of tutorials. I can't find online how to create handlers for SIGINT, SIGTERM, HUP, etc. in Erlang. 回答1: You can not. OS signals handled exclusively by Erlang VM. I guess OS signals can be handled in a driver but it can interfere with the VM signal handler so use it on your own risk. 回答2: I stumbled upon this: http://erlang.org/doc/man/kernel_app.html#erl_signal_server. I have not