/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Public Member Functions | Private Attributes
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.


Constructor & Destructor Documentation

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

Definition at line 63 of file async.py.

00064                                           :
00065         if not obj:
00066             raise ValueError,'Must give a valid object'
00067         self.__dict__['_obj'] = obj
00068         self.__dict__['_count'] = 0
00069         self.__dict__['_callbacks'] = {}
00070 
00071         if proctype:
00072             meth = eval ("self.do_%s"%proctype)
00073             meth()
00074             return
00075         else:
00076             try:
00077                 import multiprocessing
00078             except ImportError:
00079                 self.do_threaded()
00080             else:
00081                 self.do_multiprocessing()
00082                 pass
00083             pass
00084         return

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

Definition at line 117 of file async.py.

00118                      :
00119         self.shutdown()
00120         return


Member Function Documentation

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

Definition at line 85 of file async.py.

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

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

Definition at line 95 of file async.py.

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

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

Definition at line 106 of file async.py.

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

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

Definition at line 121 of file async.py.

00122                       :
00123         'Gently shutdown the real object and drain the queue'
00124         self._outbox.put(('async_caller_exit', None, None, None))
00125         self.drain_queue()
00126         self._proc.join()
00127         return

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

Definition at line 128 of file async.py.

00129                    :
00130         'Immediately shutdown'
00131         if self._proctype == 'multiproces':
00132             self._proc.terminate()
00133         import sys
00134         sys.exit(0)
00135         return

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

Definition at line 136 of file async.py.

00137                                        :
00138         'Drain queue of at most depth pending results.  All if depth=None'
00139         while depth is None or depth > 0:
00140             if depth is not None: depth -= 1
00141             if self._inbox.empty(): 
00142                 #print 'queue empty'
00143                 return
00144             cbnum, res = self._inbox.get()
00145             meth = self._callbacks[cbnum]
00146             #print 'calling',meth.callback,'number',cbnum,'with',res
00147             meth.callback(res)
00148             del self._callbacks[cbnum]
00149             continue
00150         return
00151 

Member Data Documentation

Definition at line 128 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 Fri May 16 2014 09:56:15 for EventLooper by doxygen 1.7.4