Show More
@@ -0,0 +1,45 | |||
|
1 | """ Advanced signal (e.g. ctrl+C) handling for IPython | |
|
2 | ||
|
3 | So far, this only ignores ctrl + C in IPython file a subprocess | |
|
4 | is executing, to get closer to how a "proper" shell behaves. | |
|
5 | ||
|
6 | Other signal processing may be implemented later on. | |
|
7 | ||
|
8 | If _ip.options.verbose is true, show exit status if nonzero | |
|
9 | ||
|
10 | """ | |
|
11 | ||
|
12 | import signal,os | |
|
13 | import IPython.ipapi | |
|
14 | import subprocess | |
|
15 | ||
|
16 | ip = IPython.ipapi.get() | |
|
17 | ||
|
18 | ||
|
19 | def new_ipsystem(cmd): | |
|
20 | """ ctrl+c ignoring replacement for system() command in iplib. | |
|
21 | ||
|
22 | Ignore ctrl + c in IPython process during the command execution. | |
|
23 | The subprocess will still get the ctrl + c signal. | |
|
24 | """ | |
|
25 | ||
|
26 | p = subprocess.Popen(cmd, shell = True) | |
|
27 | ||
|
28 | old_handler = signal.signal(signal.SIGINT, signal.SIG_IGN) | |
|
29 | pid,status = os.waitpid(p.pid,0) | |
|
30 | signal.signal(signal.SIGINT, old_handler) | |
|
31 | if status and ip.options.verbose: | |
|
32 | print "[exit status: %d]" % status | |
|
33 | ||
|
34 | def init(): | |
|
35 | o = ip.options | |
|
36 | try: | |
|
37 | o.verbose | |
|
38 | except AttributeError: | |
|
39 | o.allow_new_attr (True ) | |
|
40 | o.verbose = 0 | |
|
41 | ||
|
42 | ip.IP.system = new_ipsystem | |
|
43 | ||
|
44 | init() | |
|
45 | No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now