Update of /cvsroot/pywin32/pywin32/isapi
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv8097
Modified Files:
threaded_extension.py
Log Message:
Fix worker shutdown timeout logic and set all threads deamonic
Index: threaded_extension.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/isapi/threaded_extension.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** threaded_extension.py 26 Nov 2008 08:39:33 -0000 1.5
--- threaded_extension.py 2 Mar 2009 04:41:10 -0000 1.6
***************
*** 3,6 ****
--- 3,7 ----
import sys
+ import time
from isapi import isapicon, ExtensionError
import isapi.simple
***************
*** 32,35 ****
--- 33,39 ----
self.extension = extension
threading.Thread.__init__(self)
+ # We wait 15 seconds for a thread to terminate, but if it fails to,
+ # we don't want the process to hang at exit waiting for it...
+ self.setDaemon(True)
def run(self):
***************
*** 58,62 ****
"Base class for an ISAPI extension based around a thread-pool"
max_workers = 20
! worker_shutdown_wait = 15000 # 15 seconds for workers to quit. XXX - per thread!!! Fix me!
def __init__(self):
self.workers = []
--- 62,66 ----
"Base class for an ISAPI extension based around a thread-pool"
max_workers = 20
! worker_shutdown_wait = 15000 # 15 seconds for workers to quit...
def __init__(self):
self.workers = []
***************
*** 93,98 ****
for worker in self.workers:
PostQueuedCompletionStatus(self.io_req_port, 0, ISAPI_SHUTDOWN, None)
! for worker in self.workers:
! worker.join(self.worker_shutdown_wait)
self.dispatch_map = {} # break circles
CloseHandle(self.io_req_port)
--- 97,110 ----
for worker in self.workers:
PostQueuedCompletionStatus(self.io_req_port, 0, ISAPI_SHUTDOWN, None)
! # wait for them to terminate - pity we aren't using 'native' threads
! # as then we could do a smart wait - but now we need to poll....
! end_time = time.time() + self.worker_shutdown_wait/1000
! alive = self.workers
! while alive:
! if time.time() > end_time:
! # xxx - might be nice to log something here.
! break
! time.sleep(0.2)
! alive = [w for w in alive if w.isAlive()]
self.dispatch_map = {} # break circles
CloseHandle(self.io_req_port)
|