_lastsql commented out

78 views
Skip to first unread message

Andrew Willimott

unread,
May 19, 2016, 8:10:14 AM5/19/16
to web2py-developers
Just preparing to do some updates to the Teradata adapter, which is broken after the pydal restructure.

_lastsql is no longer populated, and I see it is commented out in the SQLAdapter class.   Any reason for this ?
Either the code or the doco needs to change.

Thanks

Andrew W

Giovanni Barillari

unread,
May 19, 2016, 8:41:35 AM5/19/16
to web2py-developers
As you can read from the PR https://github.com/web2py/pydal/pull/332
  • Removed _lastsql in adapters since not thread safe
In fact, new pyDAL is thread-safe while the latest release is not.
If you need _lastsql you should implement by yourself using THREAD_LOCAL

/Giovanni

Massimo DiPierro

unread,
May 19, 2016, 7:45:52 PM5/19/16
to web2py-d...@googlegroups.com
_lastsql was thread safe. The db object is local not of a thread of the http request. every http request has its own own db object and _lastsql was an attribute of db. Therefore it is thread safe. we need to put it back. It is very useful for debugging, along with timings which stores the execution time of each db request.

--
-- mail from:GoogleGroups "web2py-developers" mailing list
make speech: web2py-d...@googlegroups.com
unsubscribe: web2py-develop...@googlegroups.com
details : http://groups.google.com/group/web2py-developers
the project: http://code.google.com/p/web2py/
official : http://www.web2py.com/
---
You received this message because you are subscribed to the Google Groups "web2py-developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py-develop...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Giovanni Barillari

unread,
May 19, 2016, 9:09:28 PM5/19/16
to web2py-developers
No it wasn't. Exactly like connection and cursor.
Everything seemed thread safe just because web2py re-create a new instance of the entire DAL stack on every request. But this is not thread safe, is just a matter of creating a single instance at every request. If you use pyDAL outside web2py request flow everything change.

Connection and cursor created a lot of troubles on every pydal version before this refactoring on weppy applications with uwsgi because the instance was shared across the processes so you need to configure it with the "lazy-apps" option set to true. But still, with any pydal release you can't use multiple threads with the same DAL instance, because connection, cursors and _lastsql was stored on the instance.

Timings are still in and they works, since I rewrote them, but I can't and won't support any '_lastsql' parameter on the instance because it won't never be thread safe.

PS: if the purpose of _lastsql is just debugging, it would make more sense using the debug option and a logger, so you can see every sql instruction executed every time, not just the last one.

/Giovanni

Andrew Willimott

unread,
May 20, 2016, 12:26:15 AM5/20/16
to web2py-developers
I used it a lot for debugging, so I'll give the debug option a try.
Sorry, I can't contribute to the thread safe discussion,  I have no idea !

Andrew W

Massimo Di Pierro

unread,
May 20, 2016, 2:32:21 PM5/20/16
to web2py-developers
This is a semantic discussion. web2py creates a dal instance at every instance and every instance has it own _lastsql. So that is fine.

You can of course use pydal outiside of web2py and in that case multiple threads can use the same db object and the same _lastsql. In this case _lastsql is not thread-unsafe, but rather it gives you the last sql from the process and not from the thread that you are using. This is not dangerous. This is just a different use case than it was designed for.

How about we have a property called _lastsql of db that returns the last entry from timings (for backward compatibility)? web2py and pydal are used in many places for teaching and this functionality is critical.

Massimo

Giovanni Barillari

unread,
May 21, 2016, 6:52:45 AM5/21/16
to web2py-d...@googlegroups.com

Ok, I will push a PR in the next days.

You received this message because you are subscribed to a topic in the Google Groups "web2py-developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py-developers/W3f9F3CCREs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py-develop...@googlegroups.com.

Massimo DiPierro

unread,
May 22, 2016, 3:28:36 PM5/22/16
to web2py-d...@googlegroups.com
Thanks.

Giovanni Barillari

unread,
May 22, 2016, 5:59:15 PM5/22/16
to web2py-developers
Thanks.


details : http://groups.google.com/group/web2py-developers
the project: http://code.google.com/p/web2py/
official : http://www.web2py.com/
--- 
You received this message because you are subscribed to a topic in the Google Groups "web2py-developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py-developers/W3f9F3CCREs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py-developers+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

-- 
-- mail from:GoogleGroups "web2py-developers" mailing list
make speech: web2py-d...@googlegroups.com

details : http://groups.google.com/group/web2py-developers
the project: http://code.google.com/p/web2py/
official : http://www.web2py.com/
--- 
You received this message because you are subscribed to the Google Groups "web2py-developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py-developers+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages