Example #1
0
class GreenletTimer(ContextualTimer):
    """A timer to get CPU time per greenlet."""

    greenlet = lazy_import('greenlet')

    def detect_context(self):
        if self.greenlet:
            return id(self.greenlet.getcurrent())

    def _trace(self, event, args):
        origin, target = args
        self.pause(id(origin))
        self.resume(id(target))

    def run(self, profiler):
        self.greenlet.settrace(self._trace)
        yield
        self.greenlet.settrace(None)
Example #2
0
 class MathHolder(object):
     math = lazy_import('math')
Example #3
0
 class O(object):
     math = lazy_import('math')