@@ -122,6 +122,12 @@ signal_default_int_handler(self, arg)
122122 return NULL ;
123123}
124124
125+ static char default_int_handler_doc [] =
126+ "default_int_handler(...)\n\
127+ \n\
128+ The default handler for SIGINT instated by Python.\n\
129+ It raises KeyboardInterrupt." ;
130+
125131
126132static RETSIGTYPE
127133signal_handler (sig_num )
@@ -164,6 +170,11 @@ signal_alarm(self, args)
164170 /* alarm() returns the number of seconds remaining */
165171 return PyInt_FromLong (alarm (t ));
166172}
173+
174+ static char alarm_doc [] =
175+ "alarm(seconds)\n\
176+ \n\
177+ Arrange for SIGALRM to arrive after the given number of seconds."
167178#endif
168179
169180#ifdef HAVE_PAUSE
@@ -187,6 +198,11 @@ signal_pause(self, args)
187198 Py_INCREF (Py_None );
188199 return Py_None ;
189200}
201+ static char pause_doc [] =
202+ "pause()
203+
204+ Wait until a signal arrives .";
205+
190206#endif
191207
192208
@@ -235,9 +251,20 @@ signal_signal(self, args)
235251 return old_handler ;
236252}
237253
254+ static char signal_doc [] =
255+ "signal(sig, action) -> action\n\
256+ \n\
257+ Set the action for the given signal. The action can be SIG_DFL,\n\
258+ SIG_IGN, or a callable Python object. The previous action is\n\
259+ returned. See getsignal() for possible return values.\n\
260+ \n\
261+ *** IMPORTANT NOTICE ***\n\
262+ A signal handler function is called with two arguments:\n\
263+ the first is the signal number, the second is the interrupted stack frame." ;
264+
238265
239266static PyObject *
240- signal_get_signal (self , args )
267+ signal_getsignal (self , args )
241268 PyObject * self ; /* Not used */
242269 PyObject * args ;
243270{
@@ -255,24 +282,57 @@ signal_get_signal(self, args)
255282 return old_handler ;
256283}
257284
285+ static char getsignal_doc [] =
286+ "getsignal(sig) -> action\n\
287+ \n\
288+ Return the current action for the given signal. The return value can be:\n\
289+ SIG_IGN -- if the signal is being ignored\n\
290+ SIG_DFL -- if the default action for the signal is in effect\n\
291+ None -- if an unknown handler is in effect\n\
292+ anything else -- the callable Python object used as a handler\n\
293+ " ;
258294
259295
260296/* List of functions defined in the module */
261297static PyMethodDef signal_methods [] = {
262298#ifdef HAVE_ALARM
263- {"alarm" , signal_alarm },
299+ {"alarm" , signal_alarm , 0 , alarm_doc },
264300#endif
265- {"signal" , signal_signal },
266- {"getsignal" , signal_get_signal },
301+ {"signal" , signal_signal , 0 , signal_doc },
302+ {"getsignal" , signal_getsignal , 0 , getsignal_doc },
267303#ifdef HAVE_PAUSE
268- {"pause" , signal_pause },
304+ {"pause" , signal_pause , 0 , pause_doc },
269305#endif
270- {"default_int_handler" , signal_default_int_handler },
271- {NULL , NULL } /* sentinel */
306+ {"default_int_handler" , signal_default_int_handler , 0 ,
307+ default_int_handler_doc },
308+ {NULL , NULL } /* sentinel */
272309};
273310
274311
275312
313+ static char module_doc [] =
314+ "This module provides mechanisms to use signal handlers in Python.\n\
315+ \n\
316+ Functions:\n\
317+ \n\
318+ alarm() -- cause SIGALRM after a specified time [Unix only]\n\
319+ signal() -- set the action for a given signal\n\
320+ getsignal() -- get the signal action for a given signal\n\
321+ pause() -- wait until a signal arrives [Unix only]\n\
322+ default_int_handler() -- default SIGINT handler\n\
323+ \n\
324+ Constants:\n\
325+ \n\
326+ SIG_DFL -- used to refer to the system default handler\n\
327+ SIG_IGN -- used to ignore the signal\n\
328+ NSIG -- number of defined signals\n\
329+ \n\
330+ SIGINT, SIGTERM, etc. -- signal numbers\n\
331+ \n\
332+ *** IMPORTANT NOTICE ***\n\
333+ A signal handler function is called with two arguments:\n\
334+ the first is the signal number, the second is the interrupted stack frame." ;
335+
276336void
277337initsignal ()
278338{
@@ -285,7 +345,7 @@ initsignal()
285345#endif
286346
287347 /* Create the module and add the functions */
288- m = Py_InitModule ("signal" , signal_methods );
348+ m = Py_InitModule3 ("signal" , signal_methods , module_doc );
289349
290350 /* Add some symbolic constants to the module */
291351 d = PyModule_GetDict (m );
0 commit comments