Added updates with respect to recent changes to TimedRotatingFileHandler.
[python.git] / Parser / intrcheck.c
blobe0f3252db6c44be3e2d24a324909d75fc5f28446
2 /* Check for interrupts */
4 #include "Python.h"
6 #ifdef QUICKWIN
8 #include <io.h>
10 void
11 PyOS_InitInterrupts(void)
15 void
16 PyOS_FiniInterrupts(void)
20 int
21 PyOS_InterruptOccurred(void)
23 _wyield();
26 #define OK
28 #endif /* QUICKWIN */
30 #if defined(_M_IX86) && !defined(__QNX__)
31 #include <io.h>
32 #endif
34 #if defined(MSDOS) && !defined(QUICKWIN)
36 #ifdef __GNUC__
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
44 #include <go32.h>
46 void
47 PyOS_InitInterrupts(void)
49 _go32_want_ctrl_break(1 /* TRUE */);
52 void
53 PyOS_FiniInterrupts(void)
57 int
58 PyOS_InterruptOccurred(void)
60 return _go32_was_ctrl_break_hit();
63 #else /* !__GNUC__ */
65 /* This might work for MS-DOS (untested though): */
67 void
68 PyOS_InitInterrupts(void)
72 void
73 PyOS_FiniInterrupts(void)
77 int
78 PyOS_InterruptOccurred(void)
80 int interrupted = 0;
81 while (kbhit()) {
82 if (getch() == '\003')
83 interrupted = 1;
85 return interrupted;
88 #endif /* __GNUC__ */
90 #define OK
92 #endif /* MSDOS && !QUICKWIN */
95 #ifndef OK
97 /* Default version -- for real operating systems and for Standard C */
99 #include <stdio.h>
100 #include <string.h>
101 #include <signal.h>
103 static int interrupted;
105 void
106 PyErr_SetInterrupt(void)
108 interrupted = 1;
111 extern int PyErr_CheckSignals(void);
113 static int
114 checksignals_witharg(void * arg)
116 return PyErr_CheckSignals();
119 static void
120 intcatcher(int sig)
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;
140 PyOS_setsig(SIGINT, intcatcher);
141 Py_AddPendingCall(checksignals_witharg, NULL);
144 static void (*old_siginthandler)(int) = SIG_DFL;
146 void
147 PyOS_InitInterrupts(void)
149 if ((old_siginthandler = PyOS_setsig(SIGINT, SIG_IGN)) != SIG_IGN)
150 PyOS_setsig(SIGINT, intcatcher);
153 void
154 PyOS_FiniInterrupts(void)
156 PyOS_setsig(SIGINT, old_siginthandler);
160 PyOS_InterruptOccurred(void)
162 if (!interrupted)
163 return 0;
164 interrupted = 0;
165 return 1;
168 #endif /* !OK */
170 void
171 PyOS_AfterFork(void)
173 #ifdef WITH_THREAD
174 PyEval_ReInitThreads();
175 #endif