Update of /cvsroot/freevo/kaa/base/src/notifier
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10093

Modified Files:
        __init__.py popen.py 
Log Message:
Add signals to Process class so that it can be useful without subclassing;
add readlines() function to Process class to read lines from process
immediately rather than going through the notifier loop; kill processes
after shutdown signal emits, rather than before.


Index: __init__.py
===================================================================
RCS file: /cvsroot/freevo/kaa/base/src/notifier/__init__.py,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** __init__.py 25 Jul 2005 20:02:46 -0000      1.20
--- __init__.py 2 Aug 2005 00:35:23 -0000       1.21
***************
*** 93,98 ****
          raise SystemExit
  
-     kill_processes()
      signals["shutdown"].emit()
  
  
--- 93,100 ----
          raise SystemExit
  
      signals["shutdown"].emit()
+     # Kill processes _after_ shutdown emits to give callbacks a chance to
+     # close them properly.
+     kill_processes()
  
  

Index: popen.py
===================================================================
RCS file: /cvsroot/freevo/kaa/base/src/notifier/popen.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** popen.py    27 Jul 2005 10:13:31 -0000      1.4
--- popen.py    2 Aug 2005 00:35:23 -0000       1.5
***************
*** 56,60 ****
  
  # notifier imports
! from callback import notifier
  from thread import MainThreadCallback, is_mainthread
  
--- 56,60 ----
  
  # notifier imports
! from callback import notifier, Signal, Callback
  from thread import MainThreadCallback, is_mainthread
  
***************
*** 76,79 ****
--- 76,88 ----
          is dead.
          """
+ 
+         # Setup signal handlers for the process; allows the class to be
+         # useful without subclassing.
+         self.signals = {
+             "stderr": Signal(),
+             "stdout": Signal(),
+             "died": Signal()
+         }
+ 
          if isinstance(app, str):
              # app is a string to execute. It will be executed by 'sh -c '
***************
*** 100,107 ****
          # IO_Handler for stdout
          self.stdout = IO_Handler( 'stdout', self.child.fromchild,
!                                   self.stdout_cb, debugname )
          # IO_Handler for stderr
          self.stderr = IO_Handler( 'stderr', self.child.childerr,
!                                   self.stderr_cb, debugname )
  
          # add child to watcher
--- 109,116 ----
          # IO_Handler for stdout
          self.stdout = IO_Handler( 'stdout', self.child.fromchild,
!                                   self._handle_stdout, debugname )
          # IO_Handler for stderr
          self.stderr = IO_Handler( 'stderr', self.child.childerr,
!                                   self._handle_stderr, debugname )
  
          # add child to watcher
***************
*** 111,114 ****
--- 120,139 ----
              _watcher.append( self, self.__child_died )
  
+     def readlines(self):
+         """
+         Read lines from process immediately, rather than going through
+         notifier.
+         """
+         if not self.child or not self.is_alive():
+             return []
+ 
+         # Remove nonblock flag temporarily.
+         fcntl.fcntl( self.child.fromchild.fileno(), fcntl.F_SETFL, os.O_RDWR )
+         lines = self.child.fromchild.readlines()
+         lines = map(lambda line: line.strip(), lines)
+         fcntl.fcntl( self.child.fromchild.fileno(), fcntl.F_SETFL, 
os.O_NONBLOCK )
+ 
+         return lines
+ 
  
      def write( self, line ):
***************
*** 148,155 ****
                  log.info('sending exit command to app')
                  self.write(cmd)
!                 cb = notifier.Callback( self.__kill, 15 )
                  self.__kill_timer = notifier.addTimer( 3000, cb )
              else:
!                 cb = notifier.Callback( self.__kill, 15 )
                  self.__kill_timer = notifier.addTimer( 0, cb )
  
--- 173,180 ----
                  log.info('sending exit command to app')
                  self.write(cmd)
!                 cb = Callback( self.__kill, 15 )
                  self.__kill_timer = notifier.addTimer( 3000, cb )
              else:
!                 cb = Callback( self.__kill, 15 )
                  self.__kill_timer = notifier.addTimer( 0, cb )
  
***************
*** 169,175 ****
  
          if signal == 15:
!             cb = notifier.Callback( self.__kill, 9 )
          else:
!             cb = notifier.Callback( self.__killall, 15 )
  
          self.__kill_timer = notifier.addTimer( 3000, cb )
--- 194,200 ----
  
          if signal == 15:
!             cb = Callback( self.__kill, 9 )
          else:
!             cb = Callback( self.__killall, 15 )
  
          self.__kill_timer = notifier.addTimer( 3000, cb )
***************
*** 213,217 ****
          log.info('kill -%d %s' % ( signal, self.binary ))
          if signal == 15:
!             cb = notifier.Callback( self.__killall, 9 )
              self.__kill_timer = notifier.addTimer( 2000, cb )
          else:
--- 238,242 ----
          log.info('kill -%d %s' % ( signal, self.binary ))
          if signal == 15:
!             cb = Callback( self.__killall, 9 )
              self.__kill_timer = notifier.addTimer( 2000, cb )
          else:
***************
*** 231,238 ****
--- 256,271 ----
          if self.__kill_timer:
              notifier.removeTimer( self.__kill_timer )
+         self.signals["died"].emit()
          if self.callback:
              # call external callback on stop
              self.callback()
  
+     def _handle_stdout(self, line):
+         self.signals["stdout"].emit(line)
+         self.stdout_cb(line)
+ 
+     def _handle_stderr(self, line):
+         self.signals["stderr"].emit(line)
+         self.stderr_cb(line)
  
      def stdout_cb( self, line ):



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to