Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
8b86348d
Commit
8b86348d
authored
Jan 27, 2014
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
asyncio: document add_signal_handler/remove_signal_handler, add an example for
signals
parent
eedc1e30
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
0 deletions
+47
-0
Doc/library/asyncio-eventloop.rst
Doc/library/asyncio-eventloop.rst
+47
-0
No files found.
Doc/library/asyncio-eventloop.rst
View file @
8b86348d
...
...
@@ -325,6 +325,29 @@ Run subprocesses asynchronously using the :mod:`subprocess` module.
This method returns a :ref:`coroutine object <coroutine>`.
UNIX signals
------------
Availability: UNIX only.
.. method:: BaseEventLoop.add_signal_handler(signum, callback, \*args)
Add a handler for a signal.
Raise :exc:`ValueError` if the signal number is invalid or uncatchable.
Raise :exc:`RuntimeError` if there is a problem setting up the handler.
.. method:: BaseEventLoop.remove_signal_handler(sig)
Remove a handler for a signal.
Return ``True`` if a signal handler was removed, ``False`` if not.
.. seealso::
The :mod:`signal` module.
Executor
--------
...
...
@@ -381,3 +404,27 @@ Print ``Hello World`` every two seconds, using a callback::
:ref:`Hello World example using a coroutine <asyncio-hello-world-coroutine>`.
Example: Set signal handlers for SIGINT and SIGTERM
---------------------------------------------------
Register handlers for signals :py:data:`SIGINT` and :py:data:`SIGTERM`::
import asyncio
import functools
import os
import signal
def ask_exit(signame):
print("got signal %s: exit" % signame)
loop.stop()
loop = asyncio.get_event_loop()
for signame in ('SIGINT', 'SIGTERM'):
loop.add_signal_handler(getattr(signal, signame),
functools.partial(ask_exit, signame))
print("Event loop running forever, press CTRL+c to interrupt.")
print("pid %s: send SIGINT or SIGTERM to exit." % os.getpid())
loop.run_forever()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment