summaryrefslogtreecommitdiff
path: root/paste/httpserver.py
diff options
context:
space:
mode:
authorianb <devnull@localhost>2007-01-30 02:37:38 +0000
committerianb <devnull@localhost>2007-01-30 02:37:38 +0000
commit6e81ae88f5c1830c8ad10135bbf5c1de57e75d27 (patch)
tree3ffbdfc41aa57676b7556eff7a6acc41ffcadc94 /paste/httpserver.py
parentd0ccb2ac27fa5ea98e329d74ec3ee892efcf5f7e (diff)
downloadpaste-6e81ae88f5c1830c8ad10135bbf5c1de57e75d27.tar.gz
Add a variable to track the requests currently being processed by the httpserver (to see wedged threads)
Diffstat (limited to 'paste/httpserver.py')
-rwxr-xr-xpaste/httpserver.py21
1 files changed, 18 insertions, 3 deletions
diff --git a/paste/httpserver.py b/paste/httpserver.py
index ecd8a1e..a57f60a 100755
--- a/paste/httpserver.py
+++ b/paste/httpserver.py
@@ -20,6 +20,8 @@ if pyOpenSSL is installed, it also provides SSL capabilities.
import atexit
import socket, sys, threading, urlparse, Queue, urllib
import posixpath
+import time
+import thread
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
from SocketServer import ThreadingMixIn
from paste.util import converters
@@ -197,6 +199,13 @@ class WSGIHandlerMixin:
,'REMOTE_ADDR': self.client_address[0]
,'REMOTE_HOST': self.address_string()
}
+
+ if hasattr(self.server, 'thread_pool'):
+ # Now that we know what the request was for, we should
+ # tell the thread pool what its worker is working on
+ self.server.thread_pool.worker_tracker[thread.get_ident()][1] = self.wsgi_environ
+ self.wsgi_environ['paste.httpserver.worker_tracker'] = self.server.thread_pool.worker_tracker
+ self.wsgi_environ['paste.httpserver.nworkers'] = self.server.thread_pool.nworkers
for k, v in self.headers.items():
key = 'HTTP_' + k.replace("-","_").upper()
@@ -374,7 +383,7 @@ class ThreadPool(object):
self.workers = []
for i in range(self.nworkers):
worker = threading.Thread(target=self.worker_thread_callback,
- name=("%s worker %d" % (self.name, i)))
+ name=("worker %d" % i))
worker.setDaemon(daemon)
worker.start()
self.workers.append(worker)
@@ -382,6 +391,8 @@ class ThreadPool(object):
if not daemon:
atexit.register(self.shutdown)
+ self.worker_tracker = {}
+
def worker_thread_callback(self):
"""
Worker thread should call this method to get and process queued
@@ -392,7 +403,11 @@ class ThreadPool(object):
if runnable is ThreadPool.SHUTDOWN:
return
else:
- runnable()
+ self.worker_tracker[thread.get_ident()] = [time.time(), None]
+ try:
+ runnable()
+ finally:
+ del self.worker_tracker[thread.get_ident()]
def shutdown(self):
"""
@@ -428,7 +443,7 @@ class ThreadPoolMixIn(object):
request.setblocking(1)
# Queue processing of the request
self.thread_pool.queue.put(
- lambda: self.process_request_in_thread(request, client_address))
+ lambda: self.process_request_in_thread(request, client_address))
def process_request_in_thread(self, request, client_address):
"""