<span>&gt; &gt; However, the thread has to start a new transaction each time it</span><br><span>&gt; </span> <span>&gt; processes something - which I know how to do:</span><br><span>&gt; </span> <span>&gt;</span><br>
<span>&gt; </span> <span>&gt;     while True:</span><br><span>&gt; </span> <span>&gt;         #wait until asked to do something</span><br><span>&gt; </span> <span>&gt;         import transaction</span><br>
<span>&gt; </span> <span>&gt;         transaction.begin()</span><br><span>&gt; </span> <span>&gt;</span><br><span>&gt; </span> <span>&gt; However, the thread needs access to the root object in order to turn</span><br>
<span>&gt; </span> <span>&gt; the identifiers gotten from the requests into persistent objects...</span><br><span>&gt; </span> <span>&gt; how would I go about accessing the root object in such a circumstance?</span><br>
<span>&gt; </span> <br><span>&gt; </span> <span>You need to pass the database object to the thread, and the thread needs</span><br><span>&gt; </span> <span>to open a connection (connection = db.open()).  Then connection.root()</span><br>

<span>&gt; </span> <span>will give you the root object (or you could pass OIDs to the thread and</span><br><span>&gt; </span> <span>use connection.get(oid) to find the objects you need to work with).</span><div><br></div>
<div>That makes sense. I wasn&#39;t sure where to get a db object from so here&#39;s what</div><div>I ended up doing. Let me know if there&#39;s a better way.</div><div><br></div><div>I use paster to run the webserver, so in run.py I now have:</div>
<div><br></div><div>    GLOBAL_CONFIG = [None]</div><div><div>    def app(global_config, **settings):</div><div>        GLOBAL_CONFIG[0] = global_config</div><div>        #...</div><div><br></div><div>Now in the thread I start to do the processing I have:</div>
<div><br></div><div><div>    def proc_f(self, i):</div><div>        from repoze.zodbconn.uri import db_from_uri</div><div>        import run</div><div>        global_config = run.GLOBAL_CONFIG[0]</div><div>        uri = global_config[&#39;zodb_uri&#39;]        </div>
<div>        db = db_from_uri(uri)</div><div>        </div><div>        conn = db.open()</div><div>        app_root = conn.root()[&#39;app_root&#39;]</div></div><div><br></div>
        while True:</div><div>            #wait for request...</div><div><br></div><div>            t = conn.transaction_manager.begin()</div><div>            #do a bunch of read-only processing, queue results</div><div>
            conn.abort(t)           </div><div><br></div>&gt; Don&#39;t forget to commit or abort the transaction, and also don&#39;t forget<br>&gt; that you may need to implement some kind of retry logic if commit()<br>&gt; raises a ConflictError due to conflicting updates.<br>
<br><div>I figure since I never write anything to the database in my worker thread I can</div><div>always abort the transaction. </div><div><br></div><div>This all seems to work. Anything horribly wrong I&#39;m doing? </div>
<div><br></div><div>Thanks muchly,</div><div><div>- Claudiu
</div>
</div>