A startup puzzle
Peter Otten
__peter__ at web.de
Mon Sep 29 14:06:23 EDT 2003
Edward K. Ream wrote:
> I've just about convinced myself there is no good, clean solution to the
> following puzzle. I wonder if you agree.
If I understand you correctly, you do
leoGlobals.py
_app=None
def app():
global _app
if not _app:
# other code
_app = Application()
return _app
leoMain.py
from leoGlobals import *
app = app()
app.mainLoop()
leoOther.py
from leoGlobals import *
app().doSomething()
Does it happen that your program runs without ever creating the Application
instance? If not, there's no point in lazy creation:
leoGlobals.py
app=None
def createApp():
global app
assert not app
app = Application()
leoMain.py
from leoGlobals import *
createApp()
app.mainLoop()
leoOther.py
from leoGlobals import *
# this works iff you can ensure that leoMain.py is the
# only "entry point" to your application
app.doSomething()
If I missed something, it would probably help if you post similar code
fragments to show where the above scheme would fail to work.
Peter
More information about the Python-list
mailing list