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)
class MathHolder(object): math = lazy_import('math')
class O(object): math = lazy_import('math')