[Zope-Checkins] CVS: Zope3/lib/python/Zope/Server - ServerChannelBase.py:1.1.2.5

Shane Hathaway shane@cvs.zope.org
Fri, 5 Apr 2002 17:51:46 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/Server
In directory cvs.zope.org:/tmp/cvs-serv21444

Modified Files:
      Tag: Zope3-Server-Branch
	ServerChannelBase.py 
Log Message:
Updated to match DualModeChannel constructor, made sure active_channel attributes in instances are ignored since they would not make sense, and exposed start_task() as a method.

=== Zope3/lib/python/Zope/Server/ServerChannelBase.py 1.1.2.4 => 1.1.2.5 ===
 
     def __init__(self, server, conn, addr, adj=None, socket_map=None):
-        ChannelBaseClass.__init__(self, server, conn, addr, adj, socket_map)
+        ChannelBaseClass.__init__(self, conn, addr, adj, socket_map)
+        self.server = server
         self.last_activity = t = self.creation_time
         self.check_maintenance(t)
 
@@ -70,14 +71,14 @@
         """This hook keeps track of opened HTTP channels.
         """
         ChannelBaseClass.add_channel(self, map)
-        self.active_channels[self._fileno] = self
+        self.__class__.active_channels[self._fileno] = self
 
 
     def del_channel(self, map=None):
         """This hook keeps track of closed HTTP channels.
         """
         ChannelBaseClass.del_channel(self, map)
-        ac = self.active_channels
+        ac = self.__class__.active_channels
         fd = self._fileno
         if ac.has_key(fd):
             del ac[fd]
@@ -86,9 +87,10 @@
     def check_maintenance(self, now):
         """Performs maintenance if necessary.
         """
-        if now < self.next_channel_cleanup[0]:
+        ncc = self.__class__.next_channel_cleanup
+        if now < ncc[0]:
             return
-        self.next_channel_cleanup[0] = now + self.adj.cleanup_interval
+        ncc[0] = now + self.adj.cleanup_interval
         self.maintenance()
 
 
@@ -105,11 +107,9 @@
         """
         now = time.time()
         cutoff = now - self.adj.channel_timeout
-        class_ = self.__class__  # Kill only channels of our own class.
         for channel in self.active_channels.values():
             if (channel is not self and not channel.running_tasks and
-                channel.last_activity < cutoff and
-                isinstance(channel, class_)):
+                channel.last_activity < cutoff):
                 channel.close()
 
 
@@ -158,9 +158,17 @@
         if do_now:
             task = self.process_request(req)
             if task is not None:
-                self.running_tasks = 1
-                self.set_sync()
-                self.server.addTask(task)
+                self.start_task(task)
+
+
+    def start_task(self, task):
+        """Starts the given task.
+
+        *** For thread safety, this should only be called from the main
+        (async) thread. ***"""
+        self.running_tasks = 1
+        self.set_sync()
+        self.server.addTask(task)
 
 
     def handle_error(self):
@@ -209,7 +217,7 @@
             finally:
                 running_lock.release()
 
-            if req:
+            if req is not None:
                 task = self.process_request(req)
                 if task is not None:
                     # Add the new task.  It will service the queue.