def _memoize(self, handler, memoize, timeout, *args, **kw):
if not isinstance(handler, Event) and self.sender is not None:<EOL><INDENT>args = list(args)[:]<EOL>args.insert(<NUM_LIT:0>, self.sender)<EOL><DEDENT>if not memoize:  <EOL><INDENT>if timeout <= <NUM_LIT:0>:  <EOL><INDENT>return True, handler(*args, **kw), handler<EOL><DEDENT>result = self._timeout(timeout, handler, *args, **kw)<EOL>if isinstance(result, tuple) and len(result) == <NUM_LIT:3>:<EOL><INDENT>if isinstance(result[<NUM_LIT:1>], Exception):  <EOL><INDENT>return False, self._error(result), handler<EOL><DEDENT><DEDENT>return True, result, handler<EOL><DEDENT>else:  <EOL><INDENT>with self._mlock:  <EOL><INDENT>hash_ = hash(handler)<EOL>if hash_ in self.memoize:<EOL><INDENT>for args_, kw_, result in self.memoize[hash_]:<EOL><INDENT>if args_ == args and kw_ == kw:  <EOL><INDENT>return True, result, handler<EOL><DEDENT><DEDENT><DEDENT>if timeout <= <NUM_LIT:0>:  <EOL><INDENT>result = handler(*args, **kw)<EOL><DEDENT>else:<EOL><INDENT>result = self._timeout(timeout, handler, *args, **kw)<EOL>if isinstance(result, tuple) and len(result) == <NUM_LIT:3>:<EOL><INDENT>if isinstance(result[<NUM_LIT:1>], Exception):  <EOL><INDENT>return False, self._error(result), handler<EOL><DEDENT><DEDENT><DEDENT>if hash_ not in self.memoize:<EOL><INDENT>self.memoize[hash_] = []<EOL><DEDENT>self.memoize[hash_].append((args, kw, result))<EOL>return True, result, handler<EOL><DEDENT><DEDENT>
Caches the execution result of successful executions        
        hash = hash(handler)
        memoize = { 
            hash : ((args, kw, result), (args, kw, result), ...), 
            hash : ((args, kw, result), ...), ...                       
        }