summaryrefslogtreecommitdiffstats
path: root/Lib/socketserver.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-04-25 22:26:08 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-04-25 22:26:08 (GMT)
commite3123915297da3e87f6d62c0e0788a6b5421a5cf (patch)
treef29aeb87761b4ba6b87b9cfbc99b6bbbececee44 /Lib/socketserver.py
parentd5781076ebff95e4d1a7054d77fb87041675baf1 (diff)
downloadcpython-e3123915297da3e87f6d62c0e0788a6b5421a5cf.zip
cpython-e3123915297da3e87f6d62c0e0788a6b5421a5cf.tar.gz
cpython-e3123915297da3e87f6d62c0e0788a6b5421a5cf.tar.bz2
Merged revisions 80487,80489 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ................ r80487 | antoine.pitrou | 2010-04-26 00:01:43 +0200 (lun., 26 avril 2010) | 12 lines Merged revisions 80484 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r80484 | antoine.pitrou | 2010-04-25 23:40:32 +0200 (dim., 25 avril 2010) | 6 lines Issue #2302: Fix a race condition in SocketServer.BaseServer.shutdown, where the method could block indefinitely if called just before the event loop started running. This also fixes the occasional freezes witnessed in test_httpservers. ........ ................ r80489 | antoine.pitrou | 2010-04-26 00:19:43 +0200 (lun., 26 avril 2010) | 9 lines Merged revisions 80480 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r80480 | antoine.pitrou | 2010-04-25 23:15:50 +0200 (dim., 25 avril 2010) | 3 lines Replace a Lock with a better suited Event. ........ ................
Diffstat (limited to 'Lib/socketserver.py')
-rw-r--r--Lib/socketserver.py26
1 files changed, 14 insertions, 12 deletions
diff --git a/Lib/socketserver.py b/Lib/socketserver.py
index 92adbcf..3d32c3e 100644
--- a/Lib/socketserver.py
+++ b/Lib/socketserver.py
@@ -197,7 +197,7 @@ class BaseServer:
self.server_address = server_address
self.RequestHandlerClass = RequestHandlerClass
self.__is_shut_down = threading.Event()
- self.__serving = False
+ self.__shutdown_request = False
def server_activate(self):
"""Called by constructor to activate the server.
@@ -214,17 +214,19 @@ class BaseServer:
self.timeout. If you need to do periodic tasks, do them in
another thread.
"""
- self.__serving = True
self.__is_shut_down.clear()
- while self.__serving:
- # XXX: Consider using another file descriptor or
- # connecting to the socket to wake this up instead of
- # polling. Polling reduces our responsiveness to a
- # shutdown request and wastes cpu at all other times.
- r, w, e = select.select([self], [], [], poll_interval)
- if r:
- self._handle_request_noblock()
- self.__is_shut_down.set()
+ try:
+ while not self.__shutdown_request:
+ # XXX: Consider using another file descriptor or
+ # connecting to the socket to wake this up instead of
+ # polling. Polling reduces our responsiveness to a
+ # shutdown request and wastes cpu at all other times.
+ r, w, e = select.select([self], [], [], poll_interval)
+ if self in r:
+ self._handle_request_noblock()
+ finally:
+ self.__shutdown_request = False
+ self.__is_shut_down.set()
def shutdown(self):
"""Stops the serve_forever loop.
@@ -233,7 +235,7 @@ class BaseServer:
serve_forever() is running in another thread, or it will
deadlock.
"""
- self.__serving = False
+ self.__shutdown_request = True
self.__is_shut_down.wait()
# The distinction between handling, getting, processing and