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
1ee92832
Commit
1ee92832
authored
Jul 29, 2015
by
Robert Collins
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #23254: Document how to close the TCPServer listening socket.
Patch from Martin Panter.
parent
54d361fd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
2 deletions
+15
-2
Doc/library/socketserver.rst
Doc/library/socketserver.rst
+11
-2
Lib/test/test_socketserver.py
Lib/test/test_socketserver.py
+1
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Doc/library/socketserver.rst
View file @
1ee92832
...
@@ -33,9 +33,10 @@ Creating a server requires several steps. First, you must create a request
...
@@ -33,9 +33,10 @@ Creating a server requires several steps. First, you must create a request
handler class by subclassing the :class:`BaseRequestHandler` class and
handler class by subclassing the :class:`BaseRequestHandler` class and
overriding its :meth:`handle` method; this method will process incoming
overriding its :meth:`handle` method; this method will process incoming
requests. Second, you must instantiate one of the server classes, passing it
requests. Second, you must instantiate one of the server classes, passing it
the server's address and the request handler class.
Finally,
call the
the server's address and the request handler class.
Then
call the
:meth:`handle_request` or :meth:`serve_forever` method of the server object to
:meth:`handle_request` or :meth:`serve_forever` method of the server object to
process one or many requests.
process one or many requests. Finally, call :meth:`~BaseServer.server_close`
to close the socket.
When inheriting from :class:`ThreadingMixIn` for threaded connection behavior,
When inheriting from :class:`ThreadingMixIn` for threaded connection behavior,
you should explicitly declare how you want your threads to behave on an abrupt
you should explicitly declare how you want your threads to behave on an abrupt
...
@@ -177,6 +178,13 @@ Server Objects
...
@@ -177,6 +178,13 @@ Server Objects
Tell the :meth:`serve_forever` loop to stop and wait until it does.
Tell the :meth:`serve_forever` loop to stop and wait until it does.
.. method:: BaseServer.server_close()
Clean up the server. May be overridden.
.. versionadded:: 2.6
.. attribute:: BaseServer.address_family
.. attribute:: BaseServer.address_family
The family of protocols to which the server's socket belongs.
The family of protocols to which the server's socket belongs.
...
@@ -547,6 +555,7 @@ An example for the :class:`ThreadingMixIn` class::
...
@@ -547,6 +555,7 @@ An example for the :class:`ThreadingMixIn` class::
client(ip, port, "Hello World 3")
client(ip, port, "Hello World 3")
server.shutdown()
server.shutdown()
server.server_close()
The output of the example should look something like this::
The output of the example should look something like this::
...
...
Lib/test/test_socketserver.py
View file @
1ee92832
...
@@ -144,6 +144,7 @@ class SocketServerTest(unittest.TestCase):
...
@@ -144,6 +144,7 @@ class SocketServerTest(unittest.TestCase):
server
.
shutdown
()
server
.
shutdown
()
t
.
join
()
t
.
join
()
server
.
server_close
()
server
.
server_close
()
self
.
assertEqual
(
-
1
,
server
.
socket
.
fileno
())
if
verbose
:
print
(
"done"
)
if
verbose
:
print
(
"done"
)
def
stream_examine
(
self
,
proto
,
addr
):
def
stream_examine
(
self
,
proto
,
addr
):
...
...
Misc/NEWS
View file @
1ee92832
...
@@ -66,6 +66,9 @@ Core and Builtins
...
@@ -66,6 +66,9 @@ Core and Builtins
Library
Library
-------
-------
-
Issue
#
23254
:
Document
how
to
close
the
TCPServer
listening
socket
.
Patch
from
Martin
Panter
.
-
Issue
#
19450
:
Update
Windows
builds
to
use
SQLite
3.8.11.0
-
Issue
#
19450
:
Update
Windows
builds
to
use
SQLite
3.8.11.0
-
Issue
#
23441
:
rcompleter
now
prints
a
tab
character
instead
of
displaying
-
Issue
#
23441
:
rcompleter
now
prints
a
tab
character
instead
of
displaying
...
...
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