Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(14)

Side by Side Diff: Doc/library/signal.rst

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Doc/library/shutil.rst ('k') | Doc/library/smtplib.rst » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 :mod:`signal` --- Set handlers for asynchronous events 1 :mod:`signal` --- Set handlers for asynchronous events
2 ====================================================== 2 ======================================================
3 3
4 .. module:: signal 4 .. module:: signal
5 :synopsis: Set handlers for asynchronous events. 5 :synopsis: Set handlers for asynchronous events.
6 6
7 7
8 This module provides mechanisms to use signal handlers in Python. Some general 8 This module provides mechanisms to use signal handlers in Python. Some general
9 rules for working with signals and their handlers: 9 rules for working with signals and their handlers:
10 10
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 previously in use, and ``None`` means that the previous signal handler was no t 172 previously in use, and ``None`` means that the previous signal handler was no t
173 installed from Python. 173 installed from Python.
174 174
175 175
176 .. function:: pause() 176 .. function:: pause()
177 177
178 Cause the process to sleep until a signal is received; the appropriate handle r 178 Cause the process to sleep until a signal is received; the appropriate handle r
179 will then be called. Returns nothing. Not on Windows. (See the Unix man pag e 179 will then be called. Returns nothing. Not on Windows. (See the Unix man pag e
180 :manpage:`signal(2)`.) 180 :manpage:`signal(2)`.)
181 181
182 See also :func:`sigwait`, :func:`sigwaitinfo`, :func:`sigtimedwait` and 182 See also :func:`sigwait` and :func:`sigpending`.
183 :func:`sigpending`.
184 183
185 184
186 .. function:: pthread_kill(thread_id, signum) 185 .. function:: pthread_kill(thread_id, signum)
187 186
188 Send the signal *signum* to the thread *thread_id*, another thread in the sam e 187 Send the signal *signum* to the thread *thread_id*, another thread in the sam e
189 process as the caller. The signal is asynchronously directed to thread. 188 process as the caller. The signal is asynchronously directed to thread.
190 189
191 Use :func:`threading.get_ident()` or the :attr:`~threading.Thread.ident` 190 Use :func:`threading.get_ident()` or the :attr:`~threading.Thread.ident`
192 attribute of :attr:`threading.Thread` to get a 'thread identifier' for 191 attribute of :attr:`threading.Thread` to get a 'thread identifier' for
193 *thread_id*. 192 *thread_id*.
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 327
329 .. function:: sigwait(sigset) 328 .. function:: sigwait(sigset)
330 329
331 Suspend execution of the calling thread until the delivery of one of the 330 Suspend execution of the calling thread until the delivery of one of the
332 signals specified in the signal set *sigset*. The function accepts the signa l 331 signals specified in the signal set *sigset*. The function accepts the signa l
333 (removes it from the pending list of signals), and returns the signal number. 332 (removes it from the pending list of signals), and returns the signal number.
334 333
335 Availability: Unix (see the man page :manpage:`sigwait(3)` for further 334 Availability: Unix (see the man page :manpage:`sigwait(3)` for further
336 information). 335 information).
337 336
338 See also :func:`pause`, :func:`pthread_sigmask`, :func:`sigpending`, 337 See also :func:`pause`, :func:`pthread_sigmask` and :func:`sigpending`.
339 :func:`sigwaitinfo` and :func:`sigtimedwait`.
340 338
341 .. versionadded:: 3.3 339 .. versionadded:: 3.3
342 340
343
344 .. function:: sigwaitinfo(sigset)
345
346 Suspend execution of the calling thread until the delivery of one of the
347 signals specified in the signal set *sigset*. The function accepts the
348 signal and removes it from the pending list of signals. If one of the
349 signals in *sigset* is already pending for the calling thread, the function
350 will return immediately with information about that signal. The signal
351 handler is not called for the delivered signal. The function raises an
352 :exc:`OSError` with error number set to :const:`errno.EINTR` if it is
353 interrupted by a signal that is not in *sigset*.
354
355 The return value is an object representing the data contained in the
356 :c:type:`siginfo_t` structure, namely: :attr:`si_signo`, :attr:`si_code`,
357 :attr:`si_errno`, :attr:`si_pid`, :attr:`si_uid`, :attr:`si_status`,
358 :attr:`si_band`.
359
360 Availability: Unix (see the man page :manpage:`sigwaitinfo(2)` for further
361 information).
362
363 See also :func:`pause`, :func:`sigwait` and :func:`sigtimedwait`.
364
365 .. versionadded:: 3.3
366
367
368 .. function:: sigtimedwait(sigset, (timeout_sec, timeout_nsec))
369
370 Like :func:`sigtimedwait`, but takes a tuple of ``(seconds, nanoseconds)``
371 as an additional argument specifying a timeout. If both *timeout_sec* and
372 *timeout_nsec* are specified as :const:`0`, a poll is performed. Returns
373 :const:`None` if a timeout occurs.
374
375 Availability: Unix (see the man page :manpage:`sigtimedwait(2)` for further
376 information).
377
378 See also :func:`pause`, :func:`sigwait` and :func:`sigwaitinfo`.
379
380 .. versionadded:: 3.3
381
382 341
383 .. _signal-example: 342 .. _signal-example:
384 343
385 Example 344 Example
386 ------- 345 -------
387 346
388 Here is a minimal example program. It uses the :func:`alarm` function to limit 347 Here is a minimal example program. It uses the :func:`alarm` function to limit
389 the time spent waiting to open a file; this is useful if the file is for a 348 the time spent waiting to open a file; this is useful if the file is for a
390 serial device that may not be turned on, which would normally cause the 349 serial device that may not be turned on, which would normally cause the
391 :func:`os.open` to hang indefinitely. The solution is to set a 5-second alarm 350 :func:`os.open` to hang indefinitely. The solution is to set a 5-second alarm
392 before opening the file; if the operation takes too long, the alarm signal will 351 before opening the file; if the operation takes too long, the alarm signal will
393 be sent, and the handler raises an exception. :: 352 be sent, and the handler raises an exception. ::
394 353
395 import signal, os 354 import signal, os
396 355
397 def handler(signum, frame): 356 def handler(signum, frame):
398 print('Signal handler called with signal', signum) 357 print('Signal handler called with signal', signum)
399 raise IOError("Couldn't open device!") 358 raise IOError("Couldn't open device!")
400 359
401 # Set the signal handler and a 5-second alarm 360 # Set the signal handler and a 5-second alarm
402 signal.signal(signal.SIGALRM, handler) 361 signal.signal(signal.SIGALRM, handler)
403 signal.alarm(5) 362 signal.alarm(5)
404 363
405 # This open() may hang indefinitely 364 # This open() may hang indefinitely
406 fd = os.open('/dev/ttyS0', os.O_RDWR) 365 fd = os.open('/dev/ttyS0', os.O_RDWR)
407 366
408 signal.alarm(0) # Disable the alarm 367 signal.alarm(0) # Disable the alarm
409 368
OLDNEW
« no previous file with comments | « Doc/library/shutil.rst ('k') | Doc/library/smtplib.rst » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+