From aa5bebac850c9aee131e8e35786879c67b195edf Mon Sep 17 00:00:00 2001 From: David Rose Date: Mon, 22 Dec 2008 19:17:18 +0000 Subject: [PATCH] defer importing ProfileSession --- direct/src/task/TaskNew.py | 8 +++++++- direct/src/task/TaskOrig.py | 9 ++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/direct/src/task/TaskNew.py b/direct/src/task/TaskNew.py index 10d980daf3..d869fa8af2 100644 --- a/direct/src/task/TaskNew.py +++ b/direct/src/task/TaskNew.py @@ -9,7 +9,6 @@ __all__ = ['Task', 'TaskManager', from direct.directnotify.DirectNotifyGlobal import * from direct.showbase import ExceptionVarDump from direct.showbase.PythonUtil import * -from direct.showbase.ProfileSession import ProfileSession import signal import types import time @@ -550,6 +549,10 @@ class TaskManager: # call to get a profile session that you can modify before passing to profileFrames() if name is None: name = 'taskMgrFrameProfile' + + # Defer this import until we need it: some Python + # distributions don't provide the profile and pstats modules. + from direct.showbase.ProfileSession import ProfileSession return ProfileSession(name) def profileFrames(self, num=None, session=None, callback=None): @@ -634,6 +637,9 @@ class TaskManager: task.setArgs(taskArgs, appendTask) task.setFunction(profileInfo.taskFunc) + # Defer this import until we need it: some Python + # distributions don't provide the profile and pstats modules. + from direct.showbase.ProfileSession import ProfileSession profileSession = ProfileSession('profiled-task-%s' % task.getName(), Functor(profileInfo.taskFunc, *profileInfo.taskArgs)) ret = profileSession.run() diff --git a/direct/src/task/TaskOrig.py b/direct/src/task/TaskOrig.py index a329686c1d..6b3d0d1a45 100644 --- a/direct/src/task/TaskOrig.py +++ b/direct/src/task/TaskOrig.py @@ -21,7 +21,6 @@ from direct.directnotify.DirectNotifyGlobal import * from direct.showbase.PythonUtil import * from direct.showbase.MessengerGlobal import * from direct.showbase import ExceptionVarDump -from direct.showbase.ProfileSession import ProfileSession import time import fnmatch import string @@ -872,6 +871,10 @@ class TaskManager: doProfile = (task.id == profileInfo.taskId) # don't profile the same task twice in a row doProfile = doProfile and (not profileInfo.profiled) + + # Defer this import until we need it: some Python + # distributions don't provide the profile and pstats modules. + from direct.showbase.ProfileSession import ProfileSession if not self.taskTimerVerbose: startTime = self.trueClock.getShortTime() @@ -1034,6 +1037,10 @@ class TaskManager: # call to get a profile session that you can modify before passing to profileFrames() if name is None: name = 'taskMgrFrameProfile' + + # Defer this import until we need it: some Python + # distributions don't provide the profile and pstats modules. + from direct.showbase.ProfileSession import ProfileSession return ProfileSession(name) def profileFrames(self, num=None, session=None, callback=None):