Using DAL outside of Web2py?

19 views
Skip to first unread message

Bottiger

unread,
Sep 17, 2009, 5:44:17 PM9/17/09
to web2py-users
I need to take snapshots of a websites. This will take a couple
seconds so I need to run it in a separate process from Web2py.

So I am wondering if it is possible to use the DAL inside that
separate python program so I can update the DB when the snapshot is
complete.

Jose

unread,
Sep 17, 2009, 6:33:50 PM9/17/09
to web2py-users

Richard

unread,
Sep 17, 2009, 8:58:58 PM9/17/09
to web2py-users
that snippet duplicates the models, which could lead to maintenance
problems.

You could use your existing model with:
import os
os.chdir('/path/to/web2py/')
from gluon.shell import env
globals().update(env('you_app_name', import_models=True))

王怀玉

unread,
Dec 27, 2009, 4:45:09 AM12/27/09
to web2py
to reuse model definition in a module, so i use gluon.shell.env .
code in module is like this:
########  module code start ###############
os.chdir(/path/to/web2py/)
from gluon.shell import env
globals().update(env('my_application_name', import_models=True))
while True:
    print "count", db(db.mytable.id>0).count()
    ### no change at all when i insert a row into db.mytable
    time.sleep(5)
########  module code end ###############
then, execute the module. the problem is that when a row is inserted into db.mytable, the result printed by module doesn't change at all.

how can i solve this ? thank you very much !


mdipierro

unread,
Dec 27, 2009, 10:31:09 AM12/27/09
to web2py-users
If I understand the problem, you need to do

db.commit()

王怀玉

unread,
Dec 27, 2009, 9:15:27 PM12/27/09
to web2py
i had done as your advice.
no change at all .
you can try it by yourself.

thank you very very much !
>0).count()
>>     ### no change at all when i insert a row into db.mytable
>>     time.sleep(5)
>> ########  module code end ###############
>> then, execute the module. the problem is that when a row is inserted into db.mytable, the result printed by module doesn't change at all.
>>
>> how can i solve this ? thank you very much !
>
>--
>
>You received this message because you are subscribed to the Google Groups "web2py-users" group.
>To post to this group, send email to web...@googlegroups.com.
>To unsubscribe from this group, send email to web2py+un...@googlegroups.com.
>For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
>
>


mdipierro

unread,
Dec 27, 2009, 10:15:26 PM12/27/09
to web2py-users
How do you insert the row?
The commit goes after you insert the row.

Massimo

On Dec 27, 8:15 pm, 王怀玉 <why00...@163.com> wrote:
> i had done as your advice.
>
> no change at all .
> you can try it by yourself.
>
> thank you very very much !
>

王怀玉

unread,
Dec 28, 2009, 8:55:14 PM12/28/09
to web2py
Yes, I do, but failed .
is it ok for u ?
the database I use is mysql . Even I insert a row into mysql through mysql client manually, no change at all, either.
########  module code start ###############
os.chdir(/path/to/web2py/)
from gluon.shell import env
globals().update(env('my_application_name', import_models=True))
while True:
print "count", db(db.mytable.id>0).count()
### no change at all when i insert a row into db.mytable
time.sleep(5)
######## module code end ###############
module name is count.py
execute it with this command:
python count.py

python version is 2.5.4
web2py version is 1.72.3, 1.74.4 also failed
system is windows xp
web2py is installed from source

Thank you, mdipierro
Reply all
Reply to author
Forward
0 new messages