Yes. I will change it tonight be very very careful. This is not thread
safe that is why it not exposed. Web2py only access this variable in a
mutex lock which makes it thread safe,

On Mar 13, 4:21 pm, Yarko Tymciurak <[email protected]> wrote:
> Hi -
> We are going to rename  SQLDB._instances   to make it clearer (see attached
> thread).
>
> Since _instances is an "internal" name to a gluon defined object, there
> should be no backward compatibility issues, but I want to be sure no one is
> affected.
>
> If anyone has an opinion on what would be the "clearest" name, I'd like to
> hear.
>
> This affects code in gluon/sql.py only (as far as I see).
>
> What this variable holds:   thread id's of processes which have open
> databases.
>
> Proposed new name:
>
>    1. _by_thread
>
> so that SQLDB._by_thread[pid]  shows what connections a process has open,
>
> Let us know any objections / feedback.
>
> Regards,
> Yarko
>
> ---------- Forwarded message ----------
> From: Massimo Di Pierro <[email protected]>
> Date: Fri, Mar 13, 2009 at 4:09 PM
> Subject: Re: suggest renaming SQLDB._instances...
> To: Yarko Tymciurak <[email protected]>
>
> No objection
>
> On Mar 13, 2009, at 4:07 PM, Yarko Tymciurak wrote:
>
> Hi Massimo -
> See below.
>
> I think renaming _instances  to perhaps _by_thread  or _by_process  or
> _by_pid  would be really helpful.
>
> Can we talk about it?
>
> Thanks,
>
> Yarko
>
> P.s. ---  _connection_pools seems really clear;  I'm looking at code to see
> if I understand what _folders is intended to be, what it is for...
>
> ---------- Forwarded message ----------
> From: Yarko Tymciurak <[email protected]>
> Date: Fri, Mar 13, 2009 at 3:58 PM
> Subject: Re: [web2py:17984] Re: the need for an ID field
> To: [email protected]
>
> On Fri, Mar 13, 2009 at 8:58 AM, DenesL <[email protected]> wrote:
>
> > On Mar 13, 8:27 am, mdipierro <[email protected]> wrote:
> > > They are listed in
>
> > > SQLDB._instances[thread.id]
>
> > > Look into SQLDB._close_all_instances in sql.py
>
> > I know there is class SQLDB in gluon.sql, but what is this SQLDB
> > object?
>
> DenesL -  sounds like you need to get yourself 2 things:  ipython (really!
>  will help much) e.g.:
>
> > In [3]: d={'a':1,'b':2}
>
> >> In [4]: d
>
> > Out[4]: {'a': 1, 'b': 2}
>
> >> In [5]: d.  [type a tab to get completion, and see result below:]
>
> > d.__class__        d.__gt__           d.__reduce_ex__    d.items
>
> > d.__cmp__          d.__hash__         d.__repr__         d.iteritems
>
> > d.__contains__     d.__init__         d.__setattr__      d.iterkeys
>
> > d.__delattr__      d.__iter__         d.__setitem__      d.itervalues
>
> > d.__delitem__      d.__le__           d.__str__          d.keys
>
> > d.__doc__          d.__len__          d.clear            d.pop
>
> > d.__eq__           d.__lt__           d.copy             d.popitem
>
> > d.__ge__           d.__ne__           d.fromkeys         d.setdefault
>
> > d.__getattribute__ d.__new__          d.get              d.update
>
> > d.__getitem__      d.__reduce__       d.has_key          d.values
>
> Then the second thing you might want to get - WingIDE (are you coming to
> PyCon?  Wingware is giving away pro licenses to anyone who participates in a
> sprint;) ---   Probably Eclipse would help here equivalently, but I didn't
> have too much happiness using eclipse w/ python (so I use Wing)...
>
> Look at gluon/sql.py,  class SQLDB(SQLStorage)
>
>        _instances={}
>
> >  And, furthermore, if I have db1, db2, ...
> > len(SQLDB._instances) == 1 (???)
>
> I think the naming is unfortunate here.  It is completely reasonable to read
>  "SQLDB._instances"  and expect you are looking at the number of database
> instances.  Unfortunately, this is not what this gives you.
>
> This says you have only one SQLDB  thread.  You want to look at the number
> of connections that thread has, e.g.
>
> In [21]: SQLDB._instances.keys()
> Out[21]: [4208]
>
> In [22]: len(SQLDB._instances[4208])
> Out[22]: 2
>
> So you want something like:
>
> In [25]: for instance in SQLDB._instances.keys():
>    ....:     len(SQLDB._instances[instance])
>    ....:     pass
>    ....:
> Out[25]: 2
>
> A better choice of name for this would maybe be:  SQLDB._threads
>
> Then you would be reading things like:
>
>     len(SQLDB._threads.keys()) to say "how many threads have open databases?
>  (which reads correctly)
>     and  len(SQLDB_treads[thread_n]) to say "how many open databases does
> thread_n have?
>
>     and len(db2._threads.keys())  to say "how many threads have db2 open?
>
> I'll talk with Massimo about renaming this.   As it is,  it's an "internal"
>  (underscore) variable, so backward compatibility should not be an issue.
>  There's already a _threads list in wsgiserver, and this is a dict (you can
> return the SQLDB objects for a thread...
>
> I think we can find some name  that makes this clear.
>
> In the meantime, I hope this helps.
>
> Regards,
> Yarko
>
> P.S. --- I think I like this name; see what you think:
>
> In [25]: for thread in SQLDB._by_thread.keys():
>    ....:     len(SQLDB._by_thread[thread])
>    ....:     pass
>    ....:
> Out[25]: 2
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" 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/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to