From f3e620677e8388ca3c6867cf5f71f54c26c718df Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 9 Oct 2009 01:06:06 +0000 Subject: [PATCH] allow better console handling; download is low-pri thread --- direct/src/p3d/AppRunner.py | 12 ++++++------ direct/src/p3d/PackageInstaller.py | 4 +++- direct/src/showbase/ShowBase.py | 3 ++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/direct/src/p3d/AppRunner.py b/direct/src/p3d/AppRunner.py index cf75c4f9c8..74f75bfd88 100644 --- a/direct/src/p3d/AppRunner.py +++ b/direct/src/p3d/AppRunner.py @@ -79,6 +79,7 @@ class AppRunner(DirectObject): # setP3DFilename() is called. self.allowPythonDev = False self.interactiveConsole = False + self.initialAppImport = False self.sessionId = 0 self.packedAppEnvironmentInitialized = False @@ -368,7 +369,7 @@ class AppRunner(DirectObject): except: # Some unexpected Python exception; pass it to the # optional handler, if it is defined. - if self.exceptionHandler: + if self.exceptionHandler and not self.interactiveConsole: self.exceptionHandler() else: raise @@ -431,19 +432,18 @@ class AppRunner(DirectObject): if mainName: moduleName = mainName - # Temporarily clear this flag while we import the app, so + # Temporarily set this flag while we import the app, so # that if the app calls run() within its own main.py, it # will properly get ignored by ShowBase. - interactiveConsole = self.interactiveConsole - self.interactiveConsole = False + self.initialAppImport = True __import__(moduleName) main = sys.modules[moduleName] if hasattr(main, 'main') and callable(main.main): main.main(self) - # Now restore this flag. - self.interactiveConsole = interactiveConsole + # Now clear this flag. + self.initialAppImport = False if self.interactiveConsole: # At this point, we have successfully loaded the app. diff --git a/direct/src/p3d/PackageInstaller.py b/direct/src/p3d/PackageInstaller.py index 026488caaa..3961666195 100644 --- a/direct/src/p3d/PackageInstaller.py +++ b/direct/src/p3d/PackageInstaller.py @@ -3,6 +3,7 @@ from direct.stdpy.threading import Lock from direct.showbase.MessengerGlobal import messenger from direct.task.TaskManagerGlobal import taskMgr from direct.p3d.PackageInfo import PackageInfo +from pandac.PandaModules import TPLow class PackageInstaller(DirectObject): @@ -145,7 +146,8 @@ class PackageInstaller(DirectObject): # If the task chain hasn't yet been set up, create the # default parameters now. if not taskMgr.hasTaskChain(self.taskChain): - taskMgr.setupTaskChain(self.taskChain, numThreads = 1) + taskMgr.setupTaskChain(self.taskChain, numThreads = 1, + threadPriority = TPLow) self.callbackLock = Lock() self.calledDownloadStarted = False diff --git a/direct/src/showbase/ShowBase.py b/direct/src/showbase/ShowBase.py index 5d29f18a4a..0a4ae9f0c5 100644 --- a/direct/src/showbase/ShowBase.py +++ b/direct/src/showbase/ShowBase.py @@ -2473,7 +2473,8 @@ class ShowBase(DirectObject.DirectObject): # p3d file. When we *are* within a p3d file, the Panda # runtime has to be responsible for running the main loop, so # we can't allow the application to do it. - if self.appRunner is None or self.appRunner.dummy or self.appRunner.interactiveConsole: + if self.appRunner is None or self.appRunner.dummy or \ + (self.appRunner.interactiveConsole and not self.appRunner.initialAppImport): self.taskMgr.run()