Re: Initializing the pool?
Philip Semanchuk <[email protected]> Tue, 10 Apr 2007 10:36:49 -0400
| Newsgroups | gmane.comp.python.spyce.general |
|---|---|
| Message-ID | <[email protected]> |
On Apr 10, 2007, at 1:36 AM, Jonathan Ellis wrote: > 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'] = ... Thanks. I'm a little reluctant to write code that relies on the internals of the pool module, but I tried this anyway. Unfortunately I didn't have any luck. I tried this code in both a module that I imported via the imports=[] statement in spyceconf.py and also directly in spyceconf.py import pool s = "/tmp/PoolLog.txt" try: pool.dictpool["foo"] = "pepperpot" file(s, "w").write("pepper in pool") except Exception, ErrorInstance: ErrorInstance = str(ErrorInstance) file(s, "w").write(ErrorInstance) In both cases /tmp/PoolLog.txt indicated that I had successfully assigned to pool["foo"] but once the server was up and running, this Spyce page showed an empty list as if the assignment never happened: [[.import name=pool]] <p>[[=pool.keys()]]</p> > 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. I was wondering about that -- aside from pickle/unpickle support in non-threaded modes, how is the pool module different from simply adding a pool to the globals in spyceconf.py as below? MyPool = { } globals = { 'MyPool': MyPool } I hope I'm not asking too many questions. Thanks for all the help. Philip ------------------------------------------------------------------------- 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