[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/StartUp - SiteDefinition.py:1.2.12.1 meta.zcml:1.2.12.1

Ulrich Eck ueck@net-labs.de
Mon, 9 Dec 2002 11:11:26 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/StartUp
In directory cvs.zope.org:/tmp/cvs-serv31943

Modified Files:
      Tag: jack-e_scheduler_branch
	SiteDefinition.py meta.zcml 
Log Message:
TaskSchedule prototype:
SiteDefinition: add Handler for addThread Subdirective
meta.zcml: add Subdirective addThread
tests/testStartupDirectives: add tests for addThread



=== Zope3/lib/python/Zope/App/StartUp/SiteDefinition.py 1.2 => 1.2.12.1 ===
--- Zope3/lib/python/Zope/App/StartUp/SiteDefinition.py:1.2	Tue Nov 19 18:25:14 2002
+++ Zope3/lib/python/Zope/App/StartUp/SiteDefinition.py	Mon Dec  9 11:11:25 2002
@@ -18,6 +18,7 @@
 """
 
 import sys
+import thread
 
 # Import Configuration-related classes
 from Zope.Configuration.Action import Action
@@ -57,7 +58,9 @@
     def __init__(self, _context, name="default", threads=4):
         """Initialize is called when defineSite directive is invoked."""
         self._name = name
-        self._threads = int(threads)
+        self._thread_count = int(threads)
+
+        self._threads = []
 
         self._zodb = None
         self.useLog(_context)
@@ -79,6 +82,13 @@
         self._zodb = DB()
         return []
 
+    # This isn't really a proper directive handler. Good thing Jim didn't write it.
+    def addThread(self, _context, callable, args=''):
+        """Lets you add a custom Tread specifying a callable and args."""
+        callable = _context.resolve(callable)
+        args = args.split()
+        self._threads.append((callable, tuple(args)))
+        return []
 
     def useLog(self, _context, file=DEFAULT_LOG_FILE):
         """Lets you specify the log file to use"""
@@ -126,7 +136,7 @@
 
         # Setup the task dispatcher
         td = ThreadedTaskDispatcher()
-        td.setThreadCount(self._threads)
+        td.setThreadCount(self._thread_count)
         
         # check whether a root was already specified for this ZODB; if
         # not create one.
@@ -138,6 +148,9 @@
             server = getServerType(type)
             server.create(td, self._zodb, server_info['port'],
                           server_info['verbose'])
+
+        for callable, args in self._threads:
+            thread.start_new_thread(callable, (self._zodb, ) + args)
 
     def _initDB(self):
         """Initialize the ZODB and persistence module importer."""


=== Zope3/lib/python/Zope/App/StartUp/meta.zcml 1.2 => 1.2.12.1 ===
--- Zope3/lib/python/Zope/App/StartUp/meta.zcml:1.2	Tue Nov 19 18:25:14 2002
+++ Zope3/lib/python/Zope/App/StartUp/meta.zcml	Mon Dec  9 11:11:25 2002
@@ -16,6 +16,9 @@
       <subdirective name="addServer"
                     attributes="type port verbose logClass" />
 
+      <subdirective name="addThread"
+                    attributes="callable args" />
+      
     </directive>
 
     <directive name="registerRequestFactory"