[Zope3-dev] Re: Thread problems
Peter Mayne
PeterMayne at ap.spherion.com
Mon Oct 11 21:52:55 EDT 2004
Philipp von Weitershausen wrote:
> Peter Mayne wrote:
>
>> I'm creating a thread using the Python threading module to perform a
>> long running task.
>>
>> As soon as I attempt to modify something, I get:
>>
>> Exception in thread Thread-3:
>> Traceback (most recent call last):
>> File "/usr/local/lib/python2.3/threading.py", line 436, in __bootstrap
>> self.run()
>> File "/home/zope/zopex3/lib/python/imdb/browser/loader.py", line 47,
>> in run
>> self._loader()
>> File "/home/zope/zopex3/lib/python/imdb/browser/loader.py", line
>> 192, in loadActors_
>> parent = self.getSubfolder(ACTORS_FOLDER)
>> File "/home/zope/zopex3/lib/python/imdb/browser/loader.py", line 57,
>> in getSubfolder
>> self.context[name] = subfolder
>> AttributeError: 'zope.thread.local' object has no attribute 'interaction'
>>
>> The thread-local storage seems to be where zope.security stores its
>> stuff. How do I get my thread to inherit the right security?
>
> - start an interaction in the thread and use a participation that either
> has all privileges like SystemConfigurationParticipation (again, if you
> don't care about security) or use the participation(s) from the original
> thread that started out with a request so that the stuff that is
> executed in your thread runs under the same privileges as the original one.
>
> The functions you need to use (newInteraction, endInteraction,
> getInteraction) are in zope.security.management. The interfaces in
> zope.security.interfaces should give you some clues. And in January you
> can buy my book *wink*.
I figured all of that out from Stephan's book and looking at the source.
I was hoping you could fill in the final bit and tell me *how* to use
those functions.
I tried the obvious thing of passing the result of getInteraction() to
the thread, and doing a newInteraction() as the very first thing when
the thread starts, but I get:
Traceback (most recent call last):
File "/usr/local/lib/python2.3/threading.py", line 436, in __bootstrap
self.run()
File "/home/zope/zopex3/lib/python/imdb/browser/loader.py", line 48,
in run
self._loader()
File "/home/zope/zopex3/lib/python/imdb/browser/loader.py", line 192,
in loadActors_
newInteraction(self._interaction)
File
"/tmp/ZopeX3-3.0.0c2/build/lib.linux-i686-2.3/zope/security/management.py",
line 89, in newInteraction
File
"/tmp/ZopeX3-3.0.0c2/build/lib.linux-i686-2.3/zope/app/securitypolicy/zopepolicy.py",
line 50, in __init__
File
"/tmp/ZopeX3-3.0.0c2/build/lib.linux-i686-2.3/zope/security/simplepolicies.py",
line 30, in __init__
File
"/tmp/ZopeX3-3.0.0c2/build/lib.linux-i686-2.3/zope/security/simplepolicies.py",
line 33, in add
AttributeError: 'ZopeSecurityPolicy' object has no attribute 'interaction'
What *should* I be doing?
PJDM
--
Peter Mayne
Spherion Technology Solutions
Canberra, ACT, Australia
"You're given the form, but you have to write the sonnet yourself.
What you say is completely up to you." - Mrs. Whatsit
More information about the Zope3-dev
mailing list