[Grok-dev] Managing non-persisted objects
Leonardo Rochael Almeida
leorochael at gmail.com
Fri Jun 27 14:29:47 EDT 2008
Another aproach is to create one COM object per thread and store it in
a module-level global dictionary keyed by the thread id. Then in your
persistent class you create a method or property to do a "fetch or
create" on this dictionary.
I'd go as far as saying you don't even need to worry about locking
this module-level global dictionary before querying or modifying it
since you'd never have a race condition on the presence of the
"thread-id" keyed value, and the Python GIL would take care of the
contention on the dictionary itself.
On Fri, Jun 27, 2008 at 15:06, Kevin Teague <kevin at bud.ca> wrote:
>
> Objects that inherit from the Persistent class (grok.Application, grok.Model,
> grok.Container) *can* be stored in the ZODB. They are not automatically
> stored, you need to explicitly give them a location within the database.
> This happens by assigning the object to a container:
>
> # myobj inherits for Persistent
> # but that functionality is unused right now
> >>> myobj = MyModel()
>
> # now myobj has been stored in a ZODB database instance
> >>> root['myexistinggrokapp']['myobj'] = myobj
>
> If you have a Model class or something similar that needs to be created on
> every request to handle your COM integration, then you can write a custom
> grok.Traverser to make it so that your grok.View class has a reference to
> this object set at self.context (one approach - there are lots of other ways
> to do the integration depending upon what you need your app to do):
>
> See the section on custom Traversing in the Developer's Notes:
>
> http://grok.zope.org/documentation/developers-notes/
>
> And more reading here:
>
> http://grok.zope.org/documentation/tutorial/navigating-to-transient-objects-tutorial/
> --
> View this message in context: http://www.nabble.com/Managing-non-persisted-objects-tp18158171p18160694.html
> Sent from the Grok mailing list archive at Nabble.com.
>
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> http://mail.zope.org/mailman/listinfo/grok-dev
>
More information about the Grok-dev
mailing list