Author: dmeyer
Date: Tue Feb 13 20:47:35 2007
New Revision: 2487

Modified:
   trunk/base/src/notifier/callback.py
   trunk/base/src/notifier/event.py
   trunk/base/src/notifier/nf_wrapper.py
   trunk/base/src/notifier/sockets.py
   trunk/base/src/notifier/timer.py

Log:
Move NotifierCalback(s) to nf_wrapper to start cleanup
callback.py


Modified: trunk/base/src/notifier/callback.py
==============================================================================
--- trunk/base/src/notifier/callback.py (original)
+++ trunk/base/src/notifier/callback.py Tue Feb 13 20:47:35 2007
@@ -6,7 +6,7 @@
 #
 # -----------------------------------------------------------------------------
 # kaa.notifier - Mainloop and callbacks
-# Copyright (C) 2005, 2006 Dirk Meyer, Jason Tackaberry, et al.
+# Copyright (C) 2005-2007 Dirk Meyer, Jason Tackaberry, et al.
 #
 # First Version: Dirk Meyer <[EMAIL PROTECTED]>
 # Maintainer:    Dirk Meyer <[EMAIL PROTECTED]>
@@ -190,58 +190,6 @@
         return id(self) == id(func) or self._get_callback() == func
 
 
-class NotifierCallback(Callback):
-
-    def __init__(self, callback, *args, **kwargs):
-        super(NotifierCallback, self).__init__(callback, *args, **kwargs)
-        self._id = None
-
-        self.signals = {
-            "exception": Signal(),
-            "unregistered": Signal()
-        }
-
-
-    def active(self):
-        # callback is active if id is not None and python is not shutting down
-        # if python is in shutdown, notifier unregister could crash
-        return self._id != None and _python_shutting_down == False
-
-
-    def unregister(self):
-        # Unregister callback with notifier.  Must be implemented by 
subclasses.
-        self.signals["unregistered"].emit()
-        self._id = None
-
-
-    def __call__(self, *args, **kwargs):
-        if not self._get_callback():
-            if self.active():
-                self.unregister()
-            return False
-
-        # If there are exception handlers for this notifier callback, we
-        # catch the exception and pass it to the handler, giving it the
-        # opportunity to abort the unregistering.  If no handlers are
-        # attached and an exception is raised, it will be propagated up to
-        # our caller.
-        if self.signals["exception"].count() > 0:
-            try:
-                ret = super(NotifierCallback, self).__call__(*args, **kwargs)
-            except:
-                # If any of the exception handlers return True, then the
-                # object is not unregistered from the Notifier.  Otherwise
-                # ret = False and it will unregister.
-                ret = self.signals["exception"].emit(sys.exc_info()[1])
-        else:
-            ret = super(NotifierCallback, self).__call__(*args, **kwargs)
-        # If Notifier callbacks return False, they get unregistered.
-        if ret == False:
-            self.unregister()
-            return False
-        return True
-
-
 class WeakCallback(Callback):
 
     def __init__(self, callback, *args, **kwargs):
@@ -304,14 +252,6 @@
 
 
 
-class WeakNotifierCallback(WeakCallback, NotifierCallback):
-
-    def _weakref_destroyed(self, object):
-        if _python_shutting_down == False:
-            super(WeakNotifierCallback, self)._weakref_destroyed(object)
-            self.unregister()
-
-
 class Signal(object):
 
     # Parameters for changed callback

Modified: trunk/base/src/notifier/event.py
==============================================================================
--- trunk/base/src/notifier/event.py    (original)
+++ trunk/base/src/notifier/event.py    Tue Feb 13 20:47:35 2007
@@ -6,7 +6,7 @@
 #
 # -----------------------------------------------------------------------------
 # kaa.notifier - Mainloop and callbacks
-# Copyright (C) 2005, 2006 Dirk Meyer, Jason Tackaberry, et al.
+# Copyright (C) 2005-2007 Dirk Meyer, Jason Tackaberry, et al.
 #
 # First Version: Dirk Meyer <[EMAIL PROTECTED]>
 # Maintainer:    Dirk Meyer <[EMAIL PROTECTED]>
@@ -36,7 +36,7 @@
 import logging
 
 # kaa.notifier imports
-from callback import NotifierCallback, WeakNotifierCallback
+from nf_wrapper import NotifierCallback, WeakNotifierCallback
 from thread import MainThreadCallback, is_mainthread
 from timer import OneShotTimer
 

Modified: trunk/base/src/notifier/nf_wrapper.py
==============================================================================
--- trunk/base/src/notifier/nf_wrapper.py       (original)
+++ trunk/base/src/notifier/nf_wrapper.py       Tue Feb 13 20:47:35 2007
@@ -6,7 +6,7 @@
 #
 # -----------------------------------------------------------------------------
 # kaa.notifier - Mainloop and callbacks
-# Copyright (C) 2006 Dirk Meyer, Jason Tackaberry, et al.
+# Copyright (C) 2006-2007 Dirk Meyer, Jason Tackaberry, et al.
 #
 # First Version: Dirk Meyer <[EMAIL PROTECTED]>
 # Maintainer:    Dirk Meyer <[EMAIL PROTECTED]>
@@ -32,6 +32,82 @@
 # Python imports
 import logging
 import sys
+import atexit
+
+# notifier import
+from callback import Callback, WeakCallback, Signal
+
+# get logging object
+log = logging.getLogger('notifier')
+
+# Variable that is set to True (via atexit callback) when python interpreter
+# is in the process of shutting down.  If we're interested if the interpreter
+# is shutting down, we don't want to test that this variable is True, but
+# rather that it is not False, because as it is prefixed with an underscore,
+# the interpreter might already have deleted this variable in which case it
+# is None.
+_python_shutting_down = False
+
+
+class NotifierCallback(Callback):
+
+    def __init__(self, callback, *args, **kwargs):
+        super(NotifierCallback, self).__init__(callback, *args, **kwargs)
+        self._id = None
+
+        self.signals = {
+            "exception": Signal(),
+            "unregistered": Signal()
+        }
+
+
+    def active(self):
+        # callback is active if id is not None and python is not shutting down
+        # if python is in shutdown, notifier unregister could crash
+        return self._id != None and _python_shutting_down == False
+
+
+    def unregister(self):
+        # Unregister callback with notifier.  Must be implemented by 
subclasses.
+        self.signals["unregistered"].emit()
+        self._id = None
+
+
+    def __call__(self, *args, **kwargs):
+        if not self._get_callback():
+            if self.active():
+                self.unregister()
+            return False
+
+        # If there are exception handlers for this notifier callback, we
+        # catch the exception and pass it to the handler, giving it the
+        # opportunity to abort the unregistering.  If no handlers are
+        # attached and an exception is raised, it will be propagated up to
+        # our caller.
+        if self.signals["exception"].count() > 0:
+            try:
+                ret = super(NotifierCallback, self).__call__(*args, **kwargs)
+            except:
+                # If any of the exception handlers return True, then the
+                # object is not unregistered from the Notifier.  Otherwise
+                # ret = False and it will unregister.
+                ret = self.signals["exception"].emit(sys.exc_info()[1])
+        else:
+            ret = super(NotifierCallback, self).__call__(*args, **kwargs)
+        # If Notifier callbacks return False, they get unregistered.
+        if ret == False:
+            self.unregister()
+            return False
+        return True
+
+
+class WeakNotifierCallback(WeakCallback, NotifierCallback):
+
+    def _weakref_destroyed(self, object):
+        if _python_shutting_down == False:
+            super(WeakNotifierCallback, self)._weakref_destroyed(object)
+            self.unregister()
+
 
 class _Wrapper(object):
     def __init__(self, name):
@@ -126,3 +202,10 @@
 
     loop = notifier.loop
     step = notifier.step
+
+
+def _shutdown_weakref_destroyed():
+    global _python_shutting_down
+    _python_shutting_down = True
+
+atexit.register(_shutdown_weakref_destroyed)

Modified: trunk/base/src/notifier/sockets.py
==============================================================================
--- trunk/base/src/notifier/sockets.py  (original)
+++ trunk/base/src/notifier/sockets.py  Tue Feb 13 20:47:35 2007
@@ -6,7 +6,7 @@
 #
 # -----------------------------------------------------------------------------
 # kaa.notifier - Mainloop and callbacks
-# Copyright (C) 2005, 2006 Dirk Meyer, Jason Tackaberry, et al.
+# Copyright (C) 2005-2007 Dirk Meyer, Jason Tackaberry, et al.
 #
 # First Version: Dirk Meyer <[EMAIL PROTECTED]>
 # Maintainer:    Dirk Meyer <[EMAIL PROTECTED]>
@@ -37,7 +37,7 @@
 import logging
 
 import nf_wrapper as notifier
-from callback import NotifierCallback, WeakNotifierCallback, Callback, Signal
+from callback import Callback, Signal
 from thread import MainThreadCallback, Thread, is_mainthread
 
 # get logging object
@@ -46,7 +46,7 @@
 IO_READ   = 0
 IO_WRITE  = 1
 
-class SocketDispatcher(NotifierCallback):
+class SocketDispatcher(notifier.NotifierCallback):
 
     def __init__(self, callback, *args, **kwargs):
         super(SocketDispatcher, self).__init__(callback, *args, **kwargs)
@@ -73,7 +73,7 @@
 
 
 
-class WeakSocketDispatcher(WeakNotifierCallback, SocketDispatcher):
+class WeakSocketDispatcher(notifier.WeakNotifierCallback, SocketDispatcher):
     pass
 
 

Modified: trunk/base/src/notifier/timer.py
==============================================================================
--- trunk/base/src/notifier/timer.py    (original)
+++ trunk/base/src/notifier/timer.py    Tue Feb 13 20:47:35 2007
@@ -6,7 +6,7 @@
 #
 # -----------------------------------------------------------------------------
 # kaa.notifier - Mainloop and callbacks
-# Copyright (C) 2005, 2006 Dirk Meyer, Jason Tackaberry, et al.
+# Copyright (C) 2005-2007 Dirk Meyer, Jason Tackaberry, et al.
 #
 # First Version: Dirk Meyer <[EMAIL PROTECTED]>
 # Maintainer:    Dirk Meyer <[EMAIL PROTECTED]>
@@ -35,13 +35,12 @@
 import logging
 
 import nf_wrapper as notifier
-from callback import NotifierCallback, WeakNotifierCallback
 from thread import MainThreadCallback, is_mainthread
 
 # get logging object
 log = logging.getLogger('notifier')
 
-class Timer(NotifierCallback):
+class Timer(notifier.NotifierCallback):
 
     def __init__(self, callback, *args, **kwargs):
         super(Timer, self).__init__(callback, *args, **kwargs)
@@ -103,9 +102,9 @@
 
 
 
-class WeakTimer(WeakNotifierCallback, Timer):
+class WeakTimer(notifier.WeakNotifierCallback, Timer):
     pass
 
-class WeakOneShotTimer(WeakNotifierCallback, OneShotTimer):
+class WeakOneShotTimer(notifier.WeakNotifierCallback, OneShotTimer):
     pass
 

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to