Mercurial > cpython-lru_cache-weakref
annotate Modules/signalmodule.c @ 4566:6403c94de50d legacy-trunk
Added safeguard against failure in __del__.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 27 Nov 1996 19:39:58 +0000 |
| parents | 65d2d8e67da3 |
| children | d36250aefb82 |
| rev | line source |
|---|---|
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 /*********************************************************** |
|
2061
172ba04a5191
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
|
172ba04a5191
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
3 The Netherlands. |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 All Rights Reserved |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3654
diff
changeset
|
7 Permission to use, copy, modify, and distribute this software and its |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3654
diff
changeset
|
8 documentation for any purpose and without fee is hereby granted, |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 provided that the above copyright notice appear in all copies and that |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3654
diff
changeset
|
10 both that copyright notice and this permission notice appear in |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 supporting documentation, and that the names of Stichting Mathematisch |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3654
diff
changeset
|
12 Centrum or CWI or Corporation for National Research Initiatives or |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3654
diff
changeset
|
13 CNRI not be used in advertising or publicity pertaining to |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3654
diff
changeset
|
14 distribution of the software without specific, written prior |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3654
diff
changeset
|
15 permission. |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
16 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3654
diff
changeset
|
17 While CWI is the initial source for this software, a modified version |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3654
diff
changeset
|
18 is made available by the Corporation for National Research Initiatives |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3654
diff
changeset
|
19 (CNRI) at the Internet address ftp://ftp.python.org. |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3654
diff
changeset
|
20 |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3654
diff
changeset
|
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3654
diff
changeset
|
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3654
diff
changeset
|
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3654
diff
changeset
|
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3654
diff
changeset
|
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3654
diff
changeset
|
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3654
diff
changeset
|
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3654
diff
changeset
|
28 PERFORMANCE OF THIS SOFTWARE. |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
29 |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
30 ******************************************************************/ |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
31 |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
32 /* Signal module -- many thanks to Lance Ellinghaus */ |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 |
|
1888
be956b1efb97
* various modules: #include "Python.h" and remove most remporary
Guido van Rossum <guido@python.org>
parents:
1867
diff
changeset
|
34 #include "Python.h" |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
35 #include "intrcheck.h" |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
36 |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
37 #include <signal.h> |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
38 |
|
1678
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
39 #ifndef SIG_ERR |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
40 #define SIG_ERR ((RETSIGTYPE (*)())-1) |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
41 #endif |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
42 |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
43 #ifndef NSIG |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
44 #define NSIG (_SIGMAX + 1) /* For QNX */ |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
45 #endif |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
46 |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
47 |
|
1678
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
48 /* |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
49 NOTES ON THE INTERACTION BETWEEN SIGNALS AND THREADS |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
50 |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
51 When threads are supported, we want the following semantics: |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
52 |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
53 - only the main thread can set a signal handler |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
54 - any thread can get a signal handler |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
55 - signals are only delivered to the main thread |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
56 |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
57 I.e. we don't support "synchronous signals" like SIGFPE (catching |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
58 this doesn't make much sense in Python anyway) nor do we support |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
59 signals as a means of inter-thread communication, since not all |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
60 thread implementations support that (at least our thread library |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
61 doesn't). |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
62 |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
63 We still have the problem that in some implementations signals |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
64 generated by the keyboard (e.g. SIGINT) are delivered to all |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
65 threads (e.g. SGI), while in others (e.g. Solaris) such signals are |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
66 delivered to one random thread (an intermediate possibility would |
| 2126 | 67 be to deliver it to the main thread -- POSIX?). For now, we have |
|
1678
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
68 a working implementation that works in all three cases -- the |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
69 handler ignores signals if getpid() isn't the same as in the main |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
70 thread. XXX This is a hack. |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
71 |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
72 */ |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
73 |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
74 #ifdef WITH_THREAD |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
75 #include "thread.h" |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
76 static long main_thread; |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
77 static pid_t main_pid; |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
78 #endif |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
79 |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
80 struct PySignal_SignalArrayStruct { |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
81 int tripped; |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
82 PyObject *func; |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
83 }; |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
84 |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
85 static struct PySignal_SignalArrayStruct PySignal_SignalHandlerArray[NSIG]; |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
86 static int PySignal_IsTripped = 0; /* Speed up sigcheck() when none tripped */ |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
87 |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
88 static PyObject *PySignal_SignalDefaultHandler; |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
89 static PyObject *PySignal_SignalIgnoreHandler; |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
90 static PyObject *PySignal_DefaultIntHandler; |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
91 |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
92 static PyObject * |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
93 PySignal_CDefaultIntHandler(self, arg) |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
94 PyObject *self; |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
95 PyObject *arg; |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
96 { |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
97 PyErr_SetNone(PyExc_KeyboardInterrupt); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
98 return (PyObject *)NULL; |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
99 } |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
100 |
|
2521
e7d480cf16ba
added PyErr_SetInterrupt(); NT ifdefs
Guido van Rossum <guido@python.org>
parents:
2211
diff
changeset
|
101 void |
|
e7d480cf16ba
added PyErr_SetInterrupt(); NT ifdefs
Guido van Rossum <guido@python.org>
parents:
2211
diff
changeset
|
102 PyErr_SetInterrupt() |
|
e7d480cf16ba
added PyErr_SetInterrupt(); NT ifdefs
Guido van Rossum <guido@python.org>
parents:
2211
diff
changeset
|
103 { |
|
e7d480cf16ba
added PyErr_SetInterrupt(); NT ifdefs
Guido van Rossum <guido@python.org>
parents:
2211
diff
changeset
|
104 PySignal_IsTripped++; |
|
e7d480cf16ba
added PyErr_SetInterrupt(); NT ifdefs
Guido van Rossum <guido@python.org>
parents:
2211
diff
changeset
|
105 PySignal_SignalHandlerArray[SIGINT].tripped = 1; |
|
e7d480cf16ba
added PyErr_SetInterrupt(); NT ifdefs
Guido van Rossum <guido@python.org>
parents:
2211
diff
changeset
|
106 } |
|
e7d480cf16ba
added PyErr_SetInterrupt(); NT ifdefs
Guido van Rossum <guido@python.org>
parents:
2211
diff
changeset
|
107 |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
108 static RETSIGTYPE |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
109 PySignal_Handler(sig_num) |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
110 int sig_num; |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
111 { |
|
1678
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
112 #ifdef WITH_THREAD |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
113 /* See NOTES section above */ |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
114 if (getpid() == main_pid) { |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
115 #endif |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
116 PySignal_IsTripped++; |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
117 PySignal_SignalHandlerArray[sig_num].tripped = 1; |
|
1678
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
118 #ifdef WITH_THREAD |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
119 } |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
120 #endif |
|
1888
be956b1efb97
* various modules: #include "Python.h" and remove most remporary
Guido van Rossum <guido@python.org>
parents:
1867
diff
changeset
|
121 #ifdef SIGCHLD |
|
be956b1efb97
* various modules: #include "Python.h" and remove most remporary
Guido van Rossum <guido@python.org>
parents:
1867
diff
changeset
|
122 if (sig_num == SIGCHLD) { |
|
be956b1efb97
* various modules: #include "Python.h" and remove most remporary
Guido van Rossum <guido@python.org>
parents:
1867
diff
changeset
|
123 /* To avoid infinite recursion, this signal remains |
|
be956b1efb97
* various modules: #include "Python.h" and remove most remporary
Guido van Rossum <guido@python.org>
parents:
1867
diff
changeset
|
124 reset until explicit re-instated. |
|
be956b1efb97
* various modules: #include "Python.h" and remove most remporary
Guido van Rossum <guido@python.org>
parents:
1867
diff
changeset
|
125 Don't clear the 'func' field as it is our pointer |
|
be956b1efb97
* various modules: #include "Python.h" and remove most remporary
Guido van Rossum <guido@python.org>
parents:
1867
diff
changeset
|
126 to the Python handler... */ |
|
be956b1efb97
* various modules: #include "Python.h" and remove most remporary
Guido van Rossum <guido@python.org>
parents:
1867
diff
changeset
|
127 return; |
|
be956b1efb97
* various modules: #include "Python.h" and remove most remporary
Guido van Rossum <guido@python.org>
parents:
1867
diff
changeset
|
128 } |
|
be956b1efb97
* various modules: #include "Python.h" and remove most remporary
Guido van Rossum <guido@python.org>
parents:
1867
diff
changeset
|
129 #endif |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
130 (void *)signal(sig_num, &PySignal_Handler); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
131 } |
|
2521
e7d480cf16ba
added PyErr_SetInterrupt(); NT ifdefs
Guido van Rossum <guido@python.org>
parents:
2211
diff
changeset
|
132 |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
133 |
|
2521
e7d480cf16ba
added PyErr_SetInterrupt(); NT ifdefs
Guido van Rossum <guido@python.org>
parents:
2211
diff
changeset
|
134 #ifndef DONT_HAVE_SIG_ALARM |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
135 static PyObject * |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
136 PySignal_Alarm(self, args) |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
137 PyObject *self; /* Not used */ |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
138 PyObject *args; |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1678
diff
changeset
|
139 { |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1678
diff
changeset
|
140 int t; |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
141 if (!PyArg_Parse(args, "i", &t)) |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
142 return (PyObject *)NULL; |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
143 /* alarm() returns the number of seconds remaining */ |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
144 return PyInt_FromLong(alarm(t)); |
|
1817
20e1d296fdcc
* Modules/signalmodule.c: added pause().
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
145 } |
|
2521
e7d480cf16ba
added PyErr_SetInterrupt(); NT ifdefs
Guido van Rossum <guido@python.org>
parents:
2211
diff
changeset
|
146 #endif |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1678
diff
changeset
|
147 |
|
2521
e7d480cf16ba
added PyErr_SetInterrupt(); NT ifdefs
Guido van Rossum <guido@python.org>
parents:
2211
diff
changeset
|
148 #ifndef DONT_HAVE_SIG_PAUSE |
|
2123
fd5ab7e828fc
cosmetic changes so these modules will work with the strict new naming scheme
Guido van Rossum <guido@python.org>
parents:
2076
diff
changeset
|
149 static PyObject * |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
150 PySignal_Pause(self, args) |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
151 PyObject *self; /* Not used */ |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
152 PyObject *args; |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
153 { |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
154 if (!PyArg_NoArgs(args)) |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
155 return NULL; |
|
2123
fd5ab7e828fc
cosmetic changes so these modules will work with the strict new naming scheme
Guido van Rossum <guido@python.org>
parents:
2076
diff
changeset
|
156 Py_BEGIN_ALLOW_THREADS |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
157 pause(); |
|
2123
fd5ab7e828fc
cosmetic changes so these modules will work with the strict new naming scheme
Guido van Rossum <guido@python.org>
parents:
2076
diff
changeset
|
158 Py_END_ALLOW_THREADS |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
159 Py_INCREF(Py_None); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
160 return Py_None; |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
161 } |
|
2521
e7d480cf16ba
added PyErr_SetInterrupt(); NT ifdefs
Guido van Rossum <guido@python.org>
parents:
2211
diff
changeset
|
162 #endif |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
163 |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
164 static PyObject * |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
165 PySignal_Signal(self, args) |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
166 PyObject *self; /* Not used */ |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
167 PyObject *args; |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
168 { |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
169 PyObject *obj; |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
170 int sig_num; |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
171 PyObject *old_handler; |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
172 RETSIGTYPE (*func)(); |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
173 if (!PyArg_Parse(args, "(iO)", &sig_num, &obj)) |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
174 return (PyObject *)NULL; |
|
1678
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
175 #ifdef WITH_THREAD |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
176 if (get_thread_ident() != main_thread) { |
|
2564
7fbff52db087
use PyCallable_Check; split some lines
Guido van Rossum <guido@python.org>
parents:
2521
diff
changeset
|
177 PyErr_SetString(PyExc_ValueError, |
|
7fbff52db087
use PyCallable_Check; split some lines
Guido van Rossum <guido@python.org>
parents:
2521
diff
changeset
|
178 "signal only works in main thread"); |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
179 return (PyObject *)NULL; |
|
1678
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
180 } |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
181 #endif |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
182 if (sig_num < 1 || sig_num >= NSIG) { |
|
2564
7fbff52db087
use PyCallable_Check; split some lines
Guido van Rossum <guido@python.org>
parents:
2521
diff
changeset
|
183 PyErr_SetString(PyExc_ValueError, |
|
7fbff52db087
use PyCallable_Check; split some lines
Guido van Rossum <guido@python.org>
parents:
2521
diff
changeset
|
184 "signal number out of range"); |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
185 return (PyObject *)NULL; |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
186 } |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
187 if (obj == PySignal_SignalIgnoreHandler) |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
188 func = SIG_IGN; |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
189 else if (obj == PySignal_SignalDefaultHandler) |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
190 func = SIG_DFL; |
|
2564
7fbff52db087
use PyCallable_Check; split some lines
Guido van Rossum <guido@python.org>
parents:
2521
diff
changeset
|
191 else if (!PyCallable_Check(obj)) { |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
192 PyErr_SetString(PyExc_TypeError, |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
193 "signal handler must be signal.SIG_IGN, signal.SIG_DFL, or a callable object"); |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
194 return (PyObject *)NULL; |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
195 } |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
196 else |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
197 func = PySignal_Handler; |
|
1678
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
198 if (signal(sig_num, func) == SIG_ERR) { |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
199 PyErr_SetFromErrno(PyExc_RuntimeError); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
200 return (PyObject *)NULL; |
|
1678
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
201 } |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
202 old_handler = PySignal_SignalHandlerArray[sig_num].func; |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
203 PySignal_SignalHandlerArray[sig_num].tripped = 0; |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
204 Py_INCREF(obj); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
205 PySignal_SignalHandlerArray[sig_num].func = obj; |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
206 return old_handler; |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
207 } |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
208 |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
209 static PyObject * |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
210 PySignal_GetSignal(self, args) |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
211 PyObject *self; /* Not used */ |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
212 PyObject *args; |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
213 { |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
214 int sig_num; |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
215 PyObject *old_handler; |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
216 if (!PyArg_Parse(args, "i", &sig_num)) |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
217 return (PyObject *)NULL; |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
218 if (sig_num < 1 || sig_num >= NSIG) { |
|
2564
7fbff52db087
use PyCallable_Check; split some lines
Guido van Rossum <guido@python.org>
parents:
2521
diff
changeset
|
219 PyErr_SetString(PyExc_ValueError, |
|
7fbff52db087
use PyCallable_Check; split some lines
Guido van Rossum <guido@python.org>
parents:
2521
diff
changeset
|
220 "signal number out of range"); |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
221 return (PyObject *)NULL; |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
222 } |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
223 old_handler = PySignal_SignalHandlerArray[sig_num].func; |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
224 Py_INCREF(old_handler); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
225 return old_handler; |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
226 } |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
227 |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
228 |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
229 /* List of functions defined in the module */ |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
230 |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
231 static PyMethodDef PySignal_methods[] = { |
|
2521
e7d480cf16ba
added PyErr_SetInterrupt(); NT ifdefs
Guido van Rossum <guido@python.org>
parents:
2211
diff
changeset
|
232 #ifndef DONT_HAVE_SIG_ALARM |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
233 {"alarm", PySignal_Alarm}, |
|
2521
e7d480cf16ba
added PyErr_SetInterrupt(); NT ifdefs
Guido van Rossum <guido@python.org>
parents:
2211
diff
changeset
|
234 #endif |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
235 {"signal", PySignal_Signal}, |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
236 {"getsignal", PySignal_GetSignal}, |
|
2521
e7d480cf16ba
added PyErr_SetInterrupt(); NT ifdefs
Guido van Rossum <guido@python.org>
parents:
2211
diff
changeset
|
237 #ifndef DONT_HAVE_SIG_PAUSE |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
238 {"pause", PySignal_Pause}, |
|
2521
e7d480cf16ba
added PyErr_SetInterrupt(); NT ifdefs
Guido van Rossum <guido@python.org>
parents:
2211
diff
changeset
|
239 #endif |
|
2076
adc028b977bd
do not call newmethodobject directly
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
240 {"default_int_handler", PySignal_CDefaultIntHandler}, |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
241 {NULL, NULL} /* sentinel */ |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
242 }; |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
243 |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
244 void |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
245 initsignal() |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
246 { |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
247 PyObject *m, *d, *x; |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
248 int i; |
|
1678
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
249 |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
250 #ifdef WITH_THREAD |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
251 main_thread = get_thread_ident(); |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
252 main_pid = getpid(); |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
253 #endif |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
254 |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
255 /* Create the module and add the functions */ |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
256 m = Py_InitModule("signal", PySignal_methods); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
257 |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
258 /* Add some symbolic constants to the module */ |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
259 d = PyModule_GetDict(m); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
260 |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
261 PySignal_SignalDefaultHandler = PyInt_FromLong((long)SIG_DFL); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
262 PyDict_SetItemString(d, "SIG_DFL", PySignal_SignalDefaultHandler); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
263 PySignal_SignalIgnoreHandler = PyInt_FromLong((long)SIG_IGN); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
264 PyDict_SetItemString(d, "SIG_IGN", PySignal_SignalIgnoreHandler); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
265 PyDict_SetItemString(d, "NSIG", PyInt_FromLong((long)NSIG)); |
|
2076
adc028b977bd
do not call newmethodobject directly
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
266 PySignal_DefaultIntHandler = |
|
adc028b977bd
do not call newmethodobject directly
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
267 PyDict_GetItemString(d, "default_int_handler"); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
268 |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
269 PySignal_SignalHandlerArray[0].tripped = 0; |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
270 for (i = 1; i < NSIG; i++) { |
|
1658
a862d8f4507b
Speed up checking for signals and define intrcheck differently
Guido van Rossum <guido@python.org>
parents:
1630
diff
changeset
|
271 RETSIGTYPE (*t)(); |
|
3595
6293723205a6
Use sigaction if possible
Guido van Rossum <guido@python.org>
parents:
2564
diff
changeset
|
272 #ifdef HAVE_SIGACTION |
|
6293723205a6
Use sigaction if possible
Guido van Rossum <guido@python.org>
parents:
2564
diff
changeset
|
273 struct sigaction act; |
|
6293723205a6
Use sigaction if possible
Guido van Rossum <guido@python.org>
parents:
2564
diff
changeset
|
274 sigaction(i, 0, &act); |
|
3654
66eeab5a758c
Use correct field of sigaction struct
Guido van Rossum <guido@python.org>
parents:
3595
diff
changeset
|
275 t = act.sa_handler; |
|
3595
6293723205a6
Use sigaction if possible
Guido van Rossum <guido@python.org>
parents:
2564
diff
changeset
|
276 #else |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
277 t = signal(i, SIG_IGN); |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
278 signal(i, t); |
|
3595
6293723205a6
Use sigaction if possible
Guido van Rossum <guido@python.org>
parents:
2564
diff
changeset
|
279 #endif |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
280 PySignal_SignalHandlerArray[i].tripped = 0; |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
281 if (t == SIG_DFL) |
|
2564
7fbff52db087
use PyCallable_Check; split some lines
Guido van Rossum <guido@python.org>
parents:
2521
diff
changeset
|
282 PySignal_SignalHandlerArray[i].func = |
|
7fbff52db087
use PyCallable_Check; split some lines
Guido van Rossum <guido@python.org>
parents:
2521
diff
changeset
|
283 PySignal_SignalDefaultHandler; |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
284 else if (t == SIG_IGN) |
|
2564
7fbff52db087
use PyCallable_Check; split some lines
Guido van Rossum <guido@python.org>
parents:
2521
diff
changeset
|
285 PySignal_SignalHandlerArray[i].func = |
|
7fbff52db087
use PyCallable_Check; split some lines
Guido van Rossum <guido@python.org>
parents:
2521
diff
changeset
|
286 PySignal_SignalIgnoreHandler; |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
287 else |
|
2564
7fbff52db087
use PyCallable_Check; split some lines
Guido van Rossum <guido@python.org>
parents:
2521
diff
changeset
|
288 PySignal_SignalHandlerArray[i].func = |
|
7fbff52db087
use PyCallable_Check; split some lines
Guido van Rossum <guido@python.org>
parents:
2521
diff
changeset
|
289 Py_None; /* None of our business */ |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
290 Py_INCREF(PySignal_SignalHandlerArray[i].func); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
291 } |
|
2564
7fbff52db087
use PyCallable_Check; split some lines
Guido van Rossum <guido@python.org>
parents:
2521
diff
changeset
|
292 if (PySignal_SignalHandlerArray[SIGINT].func == |
|
7fbff52db087
use PyCallable_Check; split some lines
Guido van Rossum <guido@python.org>
parents:
2521
diff
changeset
|
293 PySignal_SignalDefaultHandler) { |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
294 /* Install default int handler */ |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
295 Py_DECREF(PySignal_SignalHandlerArray[SIGINT].func); |
|
2564
7fbff52db087
use PyCallable_Check; split some lines
Guido van Rossum <guido@python.org>
parents:
2521
diff
changeset
|
296 PySignal_SignalHandlerArray[SIGINT].func = |
|
7fbff52db087
use PyCallable_Check; split some lines
Guido van Rossum <guido@python.org>
parents:
2521
diff
changeset
|
297 PySignal_DefaultIntHandler; |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
298 Py_INCREF(PySignal_DefaultIntHandler); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
299 signal(SIGINT, &PySignal_Handler); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
300 } |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
301 |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
302 #ifdef SIGHUP |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
303 x = PyInt_FromLong(SIGHUP); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
304 PyDict_SetItemString(d, "SIGHUP", x); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
305 #endif |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
306 #ifdef SIGINT |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
307 x = PyInt_FromLong(SIGINT); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
308 PyDict_SetItemString(d, "SIGINT", x); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
309 #endif |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
310 #ifdef SIGQUIT |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
311 x = PyInt_FromLong(SIGQUIT); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
312 PyDict_SetItemString(d, "SIGQUIT", x); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
313 #endif |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
314 #ifdef SIGILL |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
315 x = PyInt_FromLong(SIGILL); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
316 PyDict_SetItemString(d, "SIGILL", x); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
317 #endif |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
318 #ifdef SIGTRAP |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
319 x = PyInt_FromLong(SIGTRAP); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
320 PyDict_SetItemString(d, "SIGTRAP", x); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
321 #endif |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
322 #ifdef SIGIOT |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
323 x = PyInt_FromLong(SIGIOT); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
324 PyDict_SetItemString(d, "SIGIOT", x); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
325 #endif |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
326 #ifdef SIGABRT |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
327 x = PyInt_FromLong(SIGABRT); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
328 PyDict_SetItemString(d, "SIGABRT", x); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
329 #endif |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
330 #ifdef SIGEMT |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
331 x = PyInt_FromLong(SIGEMT); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
332 PyDict_SetItemString(d, "SIGEMT", x); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
333 #endif |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
334 #ifdef SIGFPE |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
335 x = PyInt_FromLong(SIGFPE); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
336 PyDict_SetItemString(d, "SIGFPE", x); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
337 #endif |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
338 #ifdef SIGKILL |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
339 x = PyInt_FromLong(SIGKILL); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
340 PyDict_SetItemString(d, "SIGKILL", x); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
341 #endif |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
342 #ifdef SIGBUS |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
343 x = PyInt_FromLong(SIGBUS); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
344 PyDict_SetItemString(d, "SIGBUS", x); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
345 #endif |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
346 #ifdef SIGSEGV |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
347 x = PyInt_FromLong(SIGSEGV); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
348 PyDict_SetItemString(d, "SIGSEGV", x); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
349 #endif |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
350 #ifdef SIGSYS |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
351 x = PyInt_FromLong(SIGSYS); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
352 PyDict_SetItemString(d, "SIGSYS", x); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
353 #endif |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
354 #ifdef SIGPIPE |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
355 x = PyInt_FromLong(SIGPIPE); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
356 PyDict_SetItemString(d, "SIGPIPE", x); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
357 #endif |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
358 #ifdef SIGALRM |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
359 x = PyInt_FromLong(SIGALRM); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
360 PyDict_SetItemString(d, "SIGALRM", x); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
361 #endif |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
362 #ifdef SIGTERM |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
363 x = PyInt_FromLong(SIGTERM); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
364 PyDict_SetItemString(d, "SIGTERM", x); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
365 #endif |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
366 #ifdef SIGUSR1 |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
367 x = PyInt_FromLong(SIGUSR1); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
368 PyDict_SetItemString(d, "SIGUSR1", x); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
369 #endif |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
370 #ifdef SIGUSR2 |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
371 x = PyInt_FromLong(SIGUSR2); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
372 PyDict_SetItemString(d, "SIGUSR2", x); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
373 #endif |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
374 #ifdef SIGCLD |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
375 x = PyInt_FromLong(SIGCLD); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
376 PyDict_SetItemString(d, "SIGCLD", x); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
377 #endif |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
378 #ifdef SIGCHLD |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
379 x = PyInt_FromLong(SIGCHLD); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
380 PyDict_SetItemString(d, "SIGCHLD", x); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
381 #endif |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
382 #ifdef SIGPWR |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
383 x = PyInt_FromLong(SIGPWR); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
384 PyDict_SetItemString(d, "SIGPWR", x); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
385 #endif |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
386 #ifdef SIGIO |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
387 x = PyInt_FromLong(SIGIO); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
388 PyDict_SetItemString(d, "SIGIO", x); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
389 #endif |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
390 #ifdef SIGURG |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
391 x = PyInt_FromLong(SIGURG); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
392 PyDict_SetItemString(d, "SIGURG", x); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
393 #endif |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
394 #ifdef SIGWINCH |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
395 x = PyInt_FromLong(SIGWINCH); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
396 PyDict_SetItemString(d, "SIGWINCH", x); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
397 #endif |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
398 #ifdef SIGPOLL |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
399 x = PyInt_FromLong(SIGPOLL); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
400 PyDict_SetItemString(d, "SIGPOLL", x); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
401 #endif |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
402 #ifdef SIGSTOP |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
403 x = PyInt_FromLong(SIGSTOP); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
404 PyDict_SetItemString(d, "SIGSTOP", x); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
405 #endif |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
406 #ifdef SIGTSTP |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
407 x = PyInt_FromLong(SIGTSTP); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
408 PyDict_SetItemString(d, "SIGTSTP", x); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
409 #endif |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
410 #ifdef SIGCONT |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
411 x = PyInt_FromLong(SIGCONT); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
412 PyDict_SetItemString(d, "SIGCONT", x); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
413 #endif |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
414 #ifdef SIGTTIN |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
415 x = PyInt_FromLong(SIGTTIN); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
416 PyDict_SetItemString(d, "SIGTTIN", x); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
417 #endif |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
418 #ifdef SIGTTOU |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
419 x = PyInt_FromLong(SIGTTOU); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
420 PyDict_SetItemString(d, "SIGTTOU", x); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
421 #endif |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
422 #ifdef SIGVTALRM |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
423 x = PyInt_FromLong(SIGVTALRM); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
424 PyDict_SetItemString(d, "SIGVTALRM", x); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
425 #endif |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
426 #ifdef SIGPROF |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
427 x = PyInt_FromLong(SIGPROF); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
428 PyDict_SetItemString(d, "SIGPROF", x); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
429 #endif |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
430 #ifdef SIGCPU |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
431 x = PyInt_FromLong(SIGCPU); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
432 PyDict_SetItemString(d, "SIGCPU", x); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
433 #endif |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
434 #ifdef SIGFSZ |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
435 x = PyInt_FromLong(SIGFSZ); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
436 PyDict_SetItemString(d, "SIGFSZ", x); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
437 #endif |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
438 /* Check for errors */ |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
439 if (PyErr_Occurred()) |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
440 Py_FatalError("can't initialize module signal"); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
441 } |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
442 |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
443 int |
|
2211
eb3e61db0dda
rename sigcheck so signal handling works again
Guido van Rossum <guido@python.org>
parents:
2126
diff
changeset
|
444 PyErr_CheckSignals() |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
445 { |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
446 int i; |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
447 PyObject *f; |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
448 if (!PySignal_IsTripped) |
|
1658
a862d8f4507b
Speed up checking for signals and define intrcheck differently
Guido van Rossum <guido@python.org>
parents:
1630
diff
changeset
|
449 return 0; |
|
1678
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
450 #ifdef WITH_THREAD |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
451 if (get_thread_ident() != main_thread) |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
452 return 0; |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
453 #endif |
|
2123
fd5ab7e828fc
cosmetic changes so these modules will work with the strict new naming scheme
Guido van Rossum <guido@python.org>
parents:
2076
diff
changeset
|
454 f = PyEval_GetFrame(); |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
455 if (f == (PyObject *)NULL) |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
456 f = Py_None; |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
457 for (i = 1; i < NSIG; i++) { |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
458 if (PySignal_SignalHandlerArray[i].tripped) { |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
459 PyObject *arglist, *result; |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
460 PySignal_SignalHandlerArray[i].tripped = 0; |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
461 arglist = Py_BuildValue("(iO)", i, f); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
462 if (arglist == (PyObject *)NULL) |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
463 result = (PyObject *)NULL; |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
464 else { |
|
2564
7fbff52db087
use PyCallable_Check; split some lines
Guido van Rossum <guido@python.org>
parents:
2521
diff
changeset
|
465 result = PyEval_CallObject( |
|
7fbff52db087
use PyCallable_Check; split some lines
Guido van Rossum <guido@python.org>
parents:
2521
diff
changeset
|
466 PySignal_SignalHandlerArray[i].func, arglist); |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
467 Py_DECREF(arglist); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
468 } |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
469 if (result == (PyObject *)NULL) { |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
470 return 1; |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
471 } else { |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
472 Py_DECREF(result); |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
473 } |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
474 } |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
475 } |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
476 PySignal_IsTripped = 0; |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
477 return 0; |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
478 } |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
479 |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
480 /* Replacement for intrcheck.c functionality */ |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
481 |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
482 void |
|
2123
fd5ab7e828fc
cosmetic changes so these modules will work with the strict new naming scheme
Guido van Rossum <guido@python.org>
parents:
2076
diff
changeset
|
483 PyOS_InitInterrupts () |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
484 { |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
485 initsignal(); |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
486 } |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
487 |
|
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
488 int |
|
2123
fd5ab7e828fc
cosmetic changes so these modules will work with the strict new naming scheme
Guido van Rossum <guido@python.org>
parents:
2076
diff
changeset
|
489 PyOS_InterruptOccurred () |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
490 { |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
491 if (PySignal_SignalHandlerArray[SIGINT].tripped) { |
|
1678
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
492 #ifdef WITH_THREAD |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
493 if (get_thread_ident() != main_thread) |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
494 return 0; |
|
1f06f71904c2
* Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents:
1658
diff
changeset
|
495 #endif |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1817
diff
changeset
|
496 PySignal_SignalHandlerArray[SIGINT].tripped = 0; |
|
1658
a862d8f4507b
Speed up checking for signals and define intrcheck differently
Guido van Rossum <guido@python.org>
parents:
1630
diff
changeset
|
497 return 1; |
|
a862d8f4507b
Speed up checking for signals and define intrcheck differently
Guido van Rossum <guido@python.org>
parents:
1630
diff
changeset
|
498 } |
|
a862d8f4507b
Speed up checking for signals and define intrcheck differently
Guido van Rossum <guido@python.org>
parents:
1630
diff
changeset
|
499 return 0; |
|
1630
0202a72d994e
New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
500 } |
