On Jan 15, 2:37 am, Michael Bayer <[email protected]> wrote:
> On Jan 14, 2009, at 3:01 PM, koranthala wrote:
>
>
>
> > I understood your point and tried updating my code as mentioned.
> > My code is a medium complex one - ~2K lines
> > A problem that I see is that since I take the object and use it at
> > many (~20) places, every single place I have to have a code like -
> >                m = session.merge(o)
> >                self.data[i] = m
> > which is added.
>
> > This seems very broilerplate - and there is no easy way to avoid it -
> > without writing a get_session myself - or having a separate object for
> > it.
> > How is it handled in other projects?
> > I would be very thankful if someone can help me out here.
>
> it seems more like the general approach of your application might need  
> adjustment.   I dont know what it means in your app to "move an object  
> to another thread".  If there is just a general pool of objects that  
> are used by any particular thread, each thread should acquire an  
> object from the pool using a single method which takes a thread-bound  
> Session,  merges the requested object into the session, and returns it  
> the merged copy.   There should be no boilerplate and instead should  
> be appropriate abstractions in place such that non-threadsafe data  
> structures are not shared between threads concurrently

I understand and accept. I modified the code appropriately and now I
might have even solved a nasty bug too because of it:-)
>From reading the sqlalchemy doc, I was under the impression that
session should be considered as a local variable.
i.e. I was actually doing session = Session() in *every method* and
then closing (session.close) it. Moreover, in places where I dont need
to modify the variable, I was just calling the objects straightaway -
and since the originating session is closed, it was actually creating
a new session everytime.

---->The bug I talked about<---
I was finding that the memory was increasing quite a bit - My process
is a long running one and actually within 1 hour, I used to use thrice
the memory I started with.
Most probably because a new session is created - and then not closed .
Also, I used to find that after 1-3 hours the interpreter itself
crashes.
I ran the call after making the changes and till now (2 hrs and
counting) the memory and interpreter is fine.

Thank you very much Micheal.

Regards
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to