| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

EventLooper::async::AsyncInterface Class Reference

List of all members.

Public Member Functions

def __init__
def do_multiprocessing
def do_threaded
def __getattr__
def __del__
def shutdown
def abort
def drain_queue

Private Attributes

 _proctype

Detailed Description

Asynchronous interface to some other object (called "real" below).

Any method calls on this object, other than the ones explicitly
defined, must have as their first argument a callable object
("callback").  The method name and remaining arguments will be
queued to another object running in a different process where it
will be interpted and result in calling the method on the real
object.  The result will be queued back to this interface object
where the callback will be called with the result as its argument.

Definition at line 48 of file async.py.


Member Function Documentation

def EventLooper::async::AsyncInterface::__init__ (   self,
  obj,
  proctype = None 
)

Definition at line 51 of file async.py.

00063                                           :
00064         if not obj:
00065             raise ValueError,'Must give a valid object'
00066         self.__dict__['_obj'] = obj
00067         self.__dict__['_count'] = 0
00068         self.__dict__['_callbacks'] = {}
00069 
00070         if proctype:
00071             meth = eval ("self.do_%s"%proctype)
00072             meth()
            return

def EventLooper::async::AsyncInterface::do_multiprocessing (   self  ) 

Definition at line 73 of file async.py.

00074             :
00075             try:
00076                 import multiprocessing
00077             except ImportError:
00078                 self.do_threaded()
00079             else:
00080                 self.do_multiprocessing()
00081                 pass
00082             pass
        return

def EventLooper::async::AsyncInterface::do_threaded (   self  ) 

Definition at line 83 of file async.py.

00085                                 :
00086         from multiprocessing import Queue, Process
00087         self.__dict__['_proctype'] = 'multiprocessing'
00088         self.__dict__['_outbox'] = outbox = Queue()
00089         self.__dict__['_inbox']  = inbox  = Queue()
00090         self.__dict__['_proc'] = proc = Process(target=async_caller, 
00091                                                 args=(self._obj, outbox, inbox))
00092         proc.start()
00093         return

def EventLooper::async::AsyncInterface::__getattr__ (   self,
  name 
)

Definition at line 94 of file async.py.

00095                          :
00096         from Queue import Queue
00097         from threading import Thread
00098         self.__dict__['_proctype'] = 'threading'
00099         self.__dict__['_outbox'] = outbox = Queue()
00100         self.__dict__['_inbox']  = inbox  = Queue()
00101         self.__dict__['_proc'] = proc = Thread(target=async_caller, 
00102                                                args=(self._obj, outbox, inbox))
00103         proc.start()
00104         return

def EventLooper::async::AsyncInterface::__del__ (   self  ) 

Definition at line 105 of file async.py.

00106                                :
00107         if not self._obj:
00108             raise AttributeError,'No object'
        if not hasattr(self._obj, name):

def EventLooper::async::AsyncInterface::shutdown (   self  ) 

Definition at line 109 of file async.py.

00109                                        :
00110             msg = 'No such attribute: "%s" in "%s"'
00111             raise AttributeError, msg % (name, self._obj)
00112         self._count += 1
00113         meth = AsyncMethod(name, self._count, self._outbox)
00114         self._callbacks[self._count] = meth
00115         return meth

def EventLooper::async::AsyncInterface::abort (   self  ) 

Definition at line 116 of file async.py.

00117                      :
00118         self.shutdown()
00119         return
00120 
00121     def shutdown(self):
00122         'Gently shutdown the real object and drain the queue'
00123         self._outbox.put(('async_caller_exit', None, None, None))
        self.drain_queue()

def EventLooper::async::AsyncInterface::drain_queue (   self,
  depth = None 
)

Definition at line 124 of file async.py.

00128                    :
00129         'Immediately shutdown'
00130         if self._proctype == 'multiproces':
00131             self._proc.terminate()
00132         import sys
00133         sys.exit(0)
00134         return
00135 
00136     def drain_queue(self, depth = None):
00137         'Drain queue of at most depth pending results.  All if depth=None'
00138         while depth is None or depth > 0:
00139             if depth is not None: depth -= 1
00140             if self._inbox.empty(): 
                #print 'queue empty'


Member Data Documentation

EventLooper::async::AsyncInterface::_proctype [private]

Definition at line 118 of file async.py.


The documentation for this class was generated from the following file:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:14:18 2011 for EventLooper by doxygen 1.4.7