Magic Optimisation

Paul McGuire ptmcg at austin.rr.com
Mon Sep 5 16:27:41 CEST 2005


I still think there are savings to be had by looping inside the
try-except block, which avoids many setup/teardown exception handling
steps.  This is not so pretty in another way (repeated while on
check()), but I would be interested in your timings w.r.t. your current
code.

    def loop(self):
        self_pool_popleft = self.pool.popleft
        self_pool_append = self.pool.append
        self_call_exit_funcs = self.call_exit_funcs
        check = self.pool.__len__
        while check() > 0:
            try:
                while check() > 0:
                    task = self_pool_popleft()
                    task.next()
                    self_pool_append(task)
            except StopIteration:
                self_call_exit_funcs(task) 

-- Paul




More information about the Python-list mailing list