Re: Initializing the pool?
"Jonathan Ellis" <[email protected]> Mon, 09 Apr 2007 22:36:58 -0700
| Newsgroups | gmane.comp.python.spyce.general |
|---|---|
| Message-ID | <[email protected]> |
On Tue, 10 Apr 2007 00:49:02 -0400, "Philip Semanchuk" <[email protected]> said: > I have another problem that I hope you can help me with. I'd like to > write some code that would run once at server start to put some data in > the pool. I tried adding an InitializePool module to the list of > imports in spyceconf.py, but I can't figure out how to manipulate the > pool from a vanilla Python module. This code gives me a handle to a > pool-ish object: > > import spyce > server = spyce.getServer() > pool = server.loadModule("pool") > > # But this gives me "object does not support item assignment" > pool["foo"] = "pepperpot" loadModule returns the module class, not an instance tied to the current request. (that is what the "api" hook gives you, but since the server is still starting up at this point that doesn't help here.) But since it's just a python dict in threaded mode you can do this import pool pool.dictpool['foo'] = ... You can also add on-startup stuff to the globals dict in spyceconf.py; those keys will be directly available in .spy pages, e.g. [[= foo ]] and as attributes of api for handlers or .spy pages. -Jonathan ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV