Я нашел такое решение для отслеживания времени в App Engine - не полностью поточно-ориентированное - что вы думаете?
module.py
# coding=utf-8
## \authors Cezary K. Wagner
from threading import Lock
__indent = 0
__patched = False
def logImports():
global __patched
if __patched == True:
return
import time
import logging
# import inspect
import __builtin__
original__import__ = __builtin__.__import__
def patched__import__(name, *args):
global __indent
lock = Lock()
lock.acquire()
spaces = ' ' * (__indent * 2)
# callerFrame = inspect.currentframe().f_back
# moduleName = callerFrame.f_globals['__name__']
# lineNumber = callerFrame.f_lineno
# logging.debug('%simport start %s %s:%s.' % (spaces, name, moduleName, lineNumber))
__indent += 1
start = time.clock()
try:
module = original__import__(name, *args)
delta = time.clock() - start
# import could fail
finally:
lock.release
__indent -= 1
if delta >= 1.0:
logging.debug('%simport end %s in %ss' % (spaces, name, delta))
return module
__builtin__.__import__ = patched__import__
__patched = True
usage.py
from module import logImports
logImports()
import math