1 |
|
---|
2 | /* Check for interrupts */
|
---|
3 |
|
---|
4 | #include "Python.h"
|
---|
5 |
|
---|
6 | #ifdef QUICKWIN
|
---|
7 |
|
---|
8 | #include <io.h>
|
---|
9 |
|
---|
10 | void
|
---|
11 | PyOS_InitInterrupts(void)
|
---|
12 | {
|
---|
13 | }
|
---|
14 |
|
---|
15 | void
|
---|
16 | PyOS_FiniInterrupts(void)
|
---|
17 | {
|
---|
18 | }
|
---|
19 |
|
---|
20 | int
|
---|
21 | PyOS_InterruptOccurred(void)
|
---|
22 | {
|
---|
23 | _wyield();
|
---|
24 | }
|
---|
25 |
|
---|
26 | #define OK
|
---|
27 |
|
---|
28 | #endif /* QUICKWIN */
|
---|
29 |
|
---|
30 | #if defined(_M_IX86) && !defined(__QNX__)
|
---|
31 | #include <io.h>
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | #if defined(MSDOS) && !defined(QUICKWIN)
|
---|
35 |
|
---|
36 | #ifdef __GNUC__
|
---|
37 |
|
---|
38 | /* This is for DJGPP's GO32 extender. I don't know how to trap
|
---|
39 | * control-C (There's no API for ctrl-C, and I don't want to mess with
|
---|
40 | * the interrupt vectors.) However, this DOES catch control-break.
|
---|
41 | * --Amrit
|
---|
42 | */
|
---|
43 |
|
---|
44 | #include <go32.h>
|
---|
45 |
|
---|
46 | void
|
---|
47 | PyOS_InitInterrupts(void)
|
---|
48 | {
|
---|
49 | _go32_want_ctrl_break(1 /* TRUE */);
|
---|
50 | }
|
---|
51 |
|
---|
52 | void
|
---|
53 | PyOS_FiniInterrupts(void)
|
---|
54 | {
|
---|
55 | }
|
---|
56 |
|
---|
57 | int
|
---|
58 | PyOS_InterruptOccurred(void)
|
---|
59 | {
|
---|
60 | return _go32_was_ctrl_break_hit();
|
---|
61 | }
|
---|
62 |
|
---|
63 | #else /* !__GNUC__ */
|
---|
64 |
|
---|
65 | /* This might work for MS-DOS (untested though): */
|
---|
66 |
|
---|
67 | void
|
---|
68 | PyOS_InitInterrupts(void)
|
---|
69 | {
|
---|
70 | }
|
---|
71 |
|
---|
72 | void
|
---|
73 | PyOS_FiniInterrupts(void)
|
---|
74 | {
|
---|
75 | }
|
---|
76 |
|
---|
77 | int
|
---|
78 | PyOS_InterruptOccurred(void)
|
---|
79 | {
|
---|
80 | int interrupted = 0;
|
---|
81 | while (kbhit()) {
|
---|
82 | if (getch() == '\003')
|
---|
83 | interrupted = 1;
|
---|
84 | }
|
---|
85 | return interrupted;
|
---|
86 | }
|
---|
87 |
|
---|
88 | #endif /* __GNUC__ */
|
---|
89 |
|
---|
90 | #define OK
|
---|
91 |
|
---|
92 | #endif /* MSDOS && !QUICKWIN */
|
---|
93 |
|
---|
94 |
|
---|
95 | #ifndef OK
|
---|
96 |
|
---|
97 | /* Default version -- for real operating systems and for Standard C */
|
---|
98 |
|
---|
99 | #include <stdio.h>
|
---|
100 | #include <string.h>
|
---|
101 | #include <signal.h>
|
---|
102 |
|
---|
103 | static int interrupted;
|
---|
104 |
|
---|
105 | void
|
---|
106 | PyErr_SetInterrupt(void)
|
---|
107 | {
|
---|
108 | interrupted = 1;
|
---|
109 | }
|
---|
110 |
|
---|
111 | extern int PyErr_CheckSignals(void);
|
---|
112 |
|
---|
113 | static int
|
---|
114 | checksignals_witharg(void * arg)
|
---|
115 | {
|
---|
116 | return PyErr_CheckSignals();
|
---|
117 | }
|
---|
118 |
|
---|
119 | static void
|
---|
120 | intcatcher(int sig)
|
---|
121 | {
|
---|
122 | extern void Py_Exit(int);
|
---|
123 | static char message[] =
|
---|
124 | "python: to interrupt a truly hanging Python program, interrupt once more.\n";
|
---|
125 | switch (interrupted++) {
|
---|
126 | case 0:
|
---|
127 | break;
|
---|
128 | case 1:
|
---|
129 | #ifdef RISCOS
|
---|
130 | fprintf(stderr, message);
|
---|
131 | #else
|
---|
132 | write(2, message, strlen(message));
|
---|
133 | #endif
|
---|
134 | break;
|
---|
135 | case 2:
|
---|
136 | interrupted = 0;
|
---|
137 | Py_Exit(1);
|
---|
138 | break;
|
---|
139 | }
|
---|
140 | PyOS_setsig(SIGINT, intcatcher);
|
---|
141 | Py_AddPendingCall(checksignals_witharg, NULL);
|
---|
142 | }
|
---|
143 |
|
---|
144 | static void (*old_siginthandler)(int) = SIG_DFL;
|
---|
145 |
|
---|
146 | void
|
---|
147 | PyOS_InitInterrupts(void)
|
---|
148 | {
|
---|
149 | if ((old_siginthandler = PyOS_setsig(SIGINT, SIG_IGN)) != SIG_IGN)
|
---|
150 | PyOS_setsig(SIGINT, intcatcher);
|
---|
151 | }
|
---|
152 |
|
---|
153 | void
|
---|
154 | PyOS_FiniInterrupts(void)
|
---|
155 | {
|
---|
156 | PyOS_setsig(SIGINT, old_siginthandler);
|
---|
157 | }
|
---|
158 |
|
---|
159 | int
|
---|
160 | PyOS_InterruptOccurred(void)
|
---|
161 | {
|
---|
162 | if (!interrupted)
|
---|
163 | return 0;
|
---|
164 | interrupted = 0;
|
---|
165 | return 1;
|
---|
166 | }
|
---|
167 |
|
---|
168 | #endif /* !OK */
|
---|
169 |
|
---|
170 | void
|
---|
171 | PyOS_AfterFork(void)
|
---|
172 | {
|
---|
173 | #ifdef WITH_THREAD
|
---|
174 | PyEval_ReInitThreads();
|
---|
175 | #endif
|
---|
176 | }
|
---|