protect against no profile module

This commit is contained in:
David Rose 2012-01-13 18:21:35 +00:00
parent a2a8aacb7e
commit da7a5b6b55

View File

@ -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