From da7a5b6b5519442cf6cf0788dec3a910726b6067 Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 13 Jan 2012 18:21:35 +0000 Subject: [PATCH] protect against no profile module --- direct/src/showbase/ShowBase.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/direct/src/showbase/ShowBase.py b/direct/src/showbase/ShowBase.py index 99db6e8c91..4486e1ce73 100644 --- a/direct/src/showbase/ShowBase.py +++ b/direct/src/showbase/ShowBase.py @@ -128,13 +128,7 @@ class ShowBase(DirectObject.DirectObject): taskMgr.resumeFunc = PStatClient.resumeAfterPause if self.__dev__: - import profile, pstats - profile.Profile.bias = float(self.config.GetString("profile-bias","0")) - - - def f8(x): - return ("%"+"8.%df"%base.config.GetInt("profile-decimals",3)) % x - pstats.f8=f8 + self.__setupProfile() # If the aspect ratio is 0 or None, it means to infer the # aspect ratio from the window size. @@ -426,6 +420,21 @@ class ShowBase(DirectObject.DirectObject): def popCTrav(self): self.cTrav = self.cTravStack.pop() + def __setupProfile(self): + """ Sets up the Python profiler, if avaialable, according to + some Panda config settings. """ + + try: + import profile, pstats + except ImportError: + return + + profile.Profile.bias = float(self.config.GetString("profile-bias","0")) + + def f8(x): + return ("%"+"8.%df"%base.config.GetInt("profile-decimals",3)) % x + pstats.f8=f8 + # temp; see ToonBase.py def getExitErrorCode(self): return 0