[web2py] form submit inconsistency.

2011-01-19 Thread annet
In a controller I have got the following form function:


def create_form():
response.view='form.html'
form=SQLFORM.factory(
Field('bedrijfsnaam',length=54,requires=IS_NOT_EMPTY()),
Field('kvk_nummer',length=8),
Field('subdossiernummer',length=4,default=''),
 
Field('rechtsvorm',requires=IS_IN_DB(db,db.rechtsvorm.rechtsvorm,'%
(rechtsvorm)s',zero=None)),
Field('adressoort',requires=IS_IN_DB(db,db.adressoort.id,'%
(soort)s',orderby=db.adressoort.id,zero=None)),
Field('straat',length=42,requires=IS_NOT_EMPTY()),
Field('huisnummer',length=9,requires=IS_NOT_EMPTY()),
Field('huisnummerextensie',length=6,default=''),
 
Field('postcode_cijferdeel',type='integer',requires=IS_NOT_EMPTY()),
Field('postcode_letterdeel',length=2,requires=IS_NOT_EMPTY()),
 
Field('plaats',requires=IS_NOT_EMPTY(),widget=SQLFORM.widgets.autocomplete(request,db.plaats.plaats,min_length=2)),
Field('telefoonnummer',length=72),
Field('faxnummer',length=72),
Field('mobielnummer',length=72),
Field('email',length=72),
Field('website',length=72),
 
Field('inschrijving',length=24,requires=IS_IN_DB(db,db.inschrijving.id,'%
(inschrijving)s',zero=None)))
form[0].insert(0,TR(H4('Bedrijfsgegevens:')))
form[0][2][2].insert(0,A('already in
database?',_onmouseover="this.style.cursor='pointer';",\
_onclick="javascript:details('%s/'+$
('input[name=kvk_nummer]').val()+'/'+$
('input[name=subdossiernummer]').val())"%URL(r=request,f='retrieve')))
form[0].insert(5,TR(H4('Adresgegevens:')))
form[0].insert(13,TR(H4('Communicatiegegevens:')))
form[0].insert(19,TR(H4('Inschrijvinggegevens:')))
form[0][-1][1].append(INPUT(_type='reset',_value='Reset'))
if form.accepts(request.vars,session):
 
row=db((db.bedrijf.kvk_nummer==form.vars.kvk_nummer)&(db.bedrijf.subdossiernummer==form.vars.subdossiernummer))
\
.select(db.bedrijf.id)
if row:
response.flash='Bedrijf al in database onder id: ' +
str(row[0].id)
else:
 
id=db.bedrijf.insert(bedrijfsnaam=form.vars.bedrijfsnaam,kvk_nummer=form.vars.kvk_nummer,
\
 
subdossiernummer=form.vars.subdossiernummer,rechtsvorm=form.vars.rechtsvorm)
 
db.adres.insert(bedrijf_id=id,adressoort_id=form.vars.adressoort,straat=form.vars.straat,
\
 
huisnummer=form.vars.huisnummer,huisnummerextensie=form.vars.huisnummerextensie,
\
 
postcode_cijferdeel=form.vars.postcode_cijferdeel,postcode_letterdeel=form.vars.postcode_letterdeel,
\
plaats=form.vars.plaats)
if form.vars.telefoonnummer:
 
db.nfa.insert(bedrijf_id=id,nfatype_id=1,adres=form.vars.telefoonnummer)
if form.vars.faxnummer:
 
db.nfa.insert(bedrijf_id=id,nfatype_id=2,adres=form.vars.faxnummer)
if form.vars.mobielnummer:
 
db.nfa.insert(bedrijf_id=id,nfatype_id=3,adres=form.vars.mobielnummer)
if form.vars.email:
 
db.nfa.insert(bedrijf_id=id,nfatype_id=4,adres=form.vars.email)
 
row=db(db.contactpersoon.email==form.vars.email).select()
if row:
 
db.bedrijfcontactpersoon.insert(bedrijf_id=id,contactpersoon_id=row[0].id)
else:
 
persoon_id=db.contactpersoon.insert(aanhef='None',email=form.vars.email,subscription=True)
 
db.bedrijfcontactpersoon.insert(bedrijf_id=id,contactpersoon_id=persoon_id)
if form.vars.website:
 
db.nfa.insert(bedrijf_id=id,nfatype_id=5,adres=form.vars.website)
 
db.bedrijfinschrijving.insert(bedrijf_id=id,inschrijving_id=form.vars.inschrijving)
response.flash='records inserted'
elif form.errors:
response.flash=response.flash_formerror
return dict(form=form)


When I click the submit button, the form's behaviour isn't consistent.
Given the form validates and the records inserted flash displays, the
data are not always inserted into the database tables. Since I can not
find any pattern in this behaviour I wonder whether there is something
wrong with the form.


Kind regards,

Annet.


[web2py] Re: .../default/user/not_authorized

2011-01-19 Thread annet
Massimo,

>     if isinstance(form,FORM):
>         form[0][-1][1].append(...)


Thanks, a much better solution.


Kind regards,

Annet


Re: [web2py] Re: Long-running controllers

2011-01-19 Thread ron_m
I think there is another bug as well.

The _unlock function only unlocks the session file if it exists but leaves 
response.session_file defined. 

Later when the request cycle finishes the _try_store_on_disk function will 
still see response.session_file as active and write it but this is now 
dangerous because it was unlocked before the write and a second request from 
the same client machine could clash. This has also had the fortunate side 
effect of closing the session file so the server does not leak file 
descriptors.

I think the tail end of _try_store_on_disk and _unlock should look like 
this:

if response.session_file:
cPickle.dump(dict(self), response.session_file)
response.session_file.truncate()
self._unlock(response)

def _unlock(self, response):
if response and response.session_file:
try:
portalocker.unlock(response.session_file)
response.session_file.close()
del response.session_file
except: ### this should never happen but happens in Windows
pass

But the del response.session_file will cause an AttributeError exception so 
maybe it would be better to set it to None or change all the tests for 
response.session_file to be hasattr(response, 'session_file')

Ron



Re: [web2py] Re: Long-running controllers

2011-01-19 Thread ron_m
Oh crud, I didn't see the self._forget state variable test at the front of 
_try-store_on_disk, sorry for the noise and response.session_file is a file 
object so having it go out of scope will close it.

Ron


Re: [web2py] Re: How to pass a database object in request.vars to a function?

2011-01-19 Thread Johann Spies
Thanks for the pointer.

Regards
Johann

-- 
 May grace and peace be yours in abundance through the full knowledge of God
and of Jesus our Lord!  His divine power has given us everything we need for
life and godliness through the full knowledge of the one who called us by
his own glory and excellence.
2 Pet. 1:2b,3a


[web2py] Value of the form field

2011-01-19 Thread luifran
When I extract the value of a form field, if I've written  for example
"take helmet", I get the value of field `take_helmet, why?
The code is as follows:

 form = FORM ('name risk',
 INPUT (_name = 'name1', required = [IS_NOT_EMPTY (),
IS_UPPER ()]),
 'preventive action Name:',
 INPUT (_name = 'name2', required = [IS_NOT_EMPTY (),
IS_UPPER ()]),
 INPUT (_type = 'submit'))
 form.accepts if (request.vars, session):
 session.flash = "Form sent"
 redirect (URL ('eliminar_prevencion_riesgos', args =
(form.vars.nombre1, form.vars.nombre2)))

When I look at the value of variables, form.vars.name1,
form.vars.name2, spaces between words are filled with the symbol '_'.
How I can fix this?


Re: [web2py] Value of the form field

2011-01-19 Thread Kenneth Lundström
If you look at form.vars.name1 before passing them via redirect you´ll 
see that no replacing has been done, try with


if form.accepts (request.vars, session):
session.flash = "Form sent"
return form.vars.name1

the replacing happens in the redirect because you can´t have an URL with spaces 
in it. If you pass name1='test ing' and test2='huu huu' you would get an URL 
like

/eliminar_prevencion_riesgos/test ing/huu huu/ and thats not allowed in web2py.


Kenneth




When I extract the value of a form field, if I've written  for example
"take helmet", I get the value of field `take_helmet, why?
The code is as follows:

  form = FORM ('name risk',
  INPUT (_name = 'name1', required = [IS_NOT_EMPTY (),
IS_UPPER ()]),
  'preventive action Name:',
  INPUT (_name = 'name2', required = [IS_NOT_EMPTY (),
IS_UPPER ()]),
  INPUT (_type = 'submit'))
  form.accepts if (request.vars, session):
  session.flash = "Form sent"
  redirect (URL ('eliminar_prevencion_riesgos', args =
(form.vars.nombre1, form.vars.nombre2)))

When I look at the value of variables, form.vars.name1,
form.vars.name2, spaces between words are filled with the symbol '_'.
How I can fix this?




[web2py] Re: Value of the form field

2011-01-19 Thread luifran
Thanks, I fixed it with the next code:
redirect(URL('modificar_obra',vars=dict(a=form.vars.nombre)))

On 19 ene, 11:19, Kenneth Lundström 
wrote:
> If you look at form.vars.name1 before passing them via redirect you ll
> see that no replacing has been done, try with
>
> if form.accepts (request.vars, session):
>      session.flash = "Form sent"
>      return form.vars.name1
>
> the replacing happens in the redirect because you can t have an URL with 
> spaces in it. If you pass name1='test ing' and test2='huu huu' you would get 
> an URL like
>
> /eliminar_prevencion_riesgos/test ing/huu huu/ and thats not allowed in 
> web2py.
>
> Kenneth
>
>
>
>
>
>
>
> > When I extract the value of a form field, if I've written  for example
> > "take helmet", I get the value of field `take_helmet, why?
> > The code is as follows:
>
> >       form = FORM ('name risk',
> >                   INPUT (_name = 'name1', required = [IS_NOT_EMPTY (),
> > IS_UPPER ()]),
> >                   'preventive action Name:',
> >                   INPUT (_name = 'name2', required = [IS_NOT_EMPTY (),
> > IS_UPPER ()]),
> >                   INPUT (_type = 'submit'))
> >       form.accepts if (request.vars, session):
> >           session.flash = "Form sent"
> >           redirect (URL ('eliminar_prevencion_riesgos', args =
> > (form.vars.nombre1, form.vars.nombre2)))
>
> > When I look at the value of variables, form.vars.name1,
> > form.vars.name2, spaces between words are filled with the symbol '_'.
> > How I can fix this?


[web2py] Re: social network idea

2011-01-19 Thread blackthorne
Maybe the bookmarking networks are considerably explored. Yet, most
people don't even use the web for anything useful. All they want is
already on Facebook galleries and those "social" networks. Bookmarking
options are limited by its sources and most people sources are always
the same, you just see what your friends say and your friends that
belong to the same circles you do, often only see the very same things
you do. I dare to say there is more communication than content. This
may be the majority and it is very active but not very "dynamic" in
the sense that social networks and chat problems don't replace each
other just because they are better. People are tied with common
interests and habits. Hard to change.

This is one reason why I like StumbleUpon and twitter and sometimes,
even Chatroulette.

What I can't find?
Oddly enough, I can't find a good code snippet network.
GitHub and alikes made a great step with code sharing for full
projects. You can search for projects not code snippets.
There are many snippet managers that help you managing your snippets.
Your code snippets.

There isn't much of a link between the previous two.
A snippet manager that also allows to search for snippets in others
code.
I believe that there is room for success here for someone able to do a
cross-platform tool combining the capabilities to manage and search/
share code and a good integration.

This is a very active minority made of programmers that use their own
tools and consider functionality over the most. There is technology
for this, a public XML-RPC API, a website and some plugins for main
IDE's.
Imagine writing your code, find a problem you never solved before and,
with minimal effort be able to search for very specific code samples
that you can use to learn and even apply when appropriate, always
without leaving your Emacs...


[web2py] Re: social network idea

2011-01-19 Thread blackthorne
Maybe the bookmarking networks are considerably explored. Yet, most
people don't even use the web for anything useful. All they want is
already on Facebook galleries and those "social" networks. Bookmarking
options are limited by its sources and most people sources are always
the same, you just see what your friends say and your friends that
belong to the same circles you do, often only see the very same things
you do. I dare to say there is more communication than content. This
may be the majority and it is very active but not very "dynamic" in
the sense that social networks and chat programs don't replace each
other just because they are better. People are tied with common
interests and habits. Hard to change.

This is one reason why I like StumbleUpon and twitter and sometimes,
even Chatroulette.

What I can't find?

Oddly enough, I can't find a good code snippet network.
GitHub and alikes made a great step with code sharing for full
projects. You can search for projects not code snippets.
There are many snippet managers that help you managing your snippets.
Your code snippets.
There isn't much of a link between the previous two.

A snippet manager that also allows to search for snippets in others
code. I believe that there is room for success here for someone able
to do a cross-platform tool combining the capabilities to manage and
search/
share code and a good integration. This is a very active minority made
of programmers that use their own tools and consider functionality
over the most. There is technology for this, a public XML-RPC API, a
website and some plugins for main IDE's. I also believe this would be
great for ourselves and for web2py visibility if this website used it.

Imagine writing your code, find a problem you never solved before and,
with minimal effort be able to search for very specific code samples
that you can use to learn and even apply when appropriate, always
without leaving your Emacs...


[web2py] web2py website and 404's

2011-01-19 Thread Albert Abril
Just a suggestion.

When I an incorrect url, for example:
http://web2py.com/layout  (instead of http://web2py.com/layouts)

...appears an "invalid controller" error, as it's expected.

What if it instead is shown a nicer 404?

Regards.


[web2py] Re: EAV Patterns

2011-01-19 Thread Adamski
Yes SQLAlchemy is exactly what I am looking for. Can anybody give me
pointers in extending SQLFORM to automatically build crud forms from
my sqlalchemy objects, I am using declarative_base to build my models.

On Jan 13, 2:23 pm, "Arun K.Rajeevan"  wrote:
> May be you like SQLAlchemy and Elixir (it's not web2py specific, but web2py
> will work with it instead of DAL)


[web2py] Re: Long-running controllers

2011-01-19 Thread ae
On Jan 18, 11:21 pm, Anthony  wrote:
> Am I missing something?

Yes.  You're probably running web2py with the default number of
threads (30 I think?).

Your 2nd browser window's cookie is unlikely to get associated to the
same thread.

I have lots of users and when one thread takes a long time, some users
can keep accessing controller functions and some can't.  Once the long-
running controller finishes, everyone can access stuff again.

If you limit the number of threads to 2 and run several browser
windows you'll see that even if one thread is free some of your
windows won't use the free one and some will.


[web2py] Re: Long-running controllers

2011-01-19 Thread ae
> No, a cookie is associated with a session.

Agreed.  I'm pretty much using 'cookie', 'user', 'session', and
'browser' as interchangeable for my purposes.  A cookie is associated
to a session, but somehow a session is associated to a thread.  Either
that or I'm seeing some other effect for which I can't imagine a
cause.


> For all practical purposes, each request gets its own thread (in practice, 
> threads are recycled through a thread pool, but that's just for efficiency). 
> Threads themselves don't retain any meaningful identity from one request to 
> the next.

I don't suspect that threads retain any state between requests.  That
wouldn't make sense given what I've described.  I imagine that
whatever dispatches requests to threads keeps an association between
session and thread.  I have not (and will not) read this code to prove
this claim because I don't care.  I'm simply explaining my assumptions
give what I've witnessed (e.g.: given two threads, some broswers can
run any controller function (other than the thread that blocks) and
others can't when just one thread is blocked/busy and the other is
free.)

Also, as I've said before, I think this would be a generally good
thing for security.  If a user can consume as many threads as he likes
he can take your entire application down (intentionally or because
he's impatient and keeps clicking a button).



Re: [web2py] Re: form / subform / adding row (field)...

2011-01-19 Thread Richard Vézina
;-) Originellement oui...

I would tell you on the orther thread that I post this one... I will do it
just for the one that fall on the orther thread so they could keep track...

I continue today working on this.

Richard

On Wed, Jan 19, 2011 at 12:30 AM, mart  wrote:

> Hey, es-tu de Montreal?
>
> On Jan 18, 7:08 pm, Richard Vézina 
> wrote:
> > I forgot to paste :
> >
> > def register():
> > form=SQLFORM.factory(db.client, db.address, formstyle = 'divs') #,
> > table_name='dummy_name')
> > if form.accepts(request.vars):
> > id = db.client.insert(**db.client._filter_fields(form.vars))
> > form.vars.client=id
> > id = db.address.insert(**db.address._filter_fields(form.vars))
> > response.flash='Thanks for filling the form'
> > return dict(form=form)
> >
> > What to do for what in red?
> >
> > I think _filter_fields is the key of the problem...
> >
> > I didn't have a look to it actually...
> >
> > Richard
> >
> > On Tue, Jan 18, 2011 at 7:00 PM, Richard Vézina <
> ml.richard.vez...@gmail.com
> >
> >
> >
> >
> >
> >
> >
> > > wrote:
> > > Hello Massimo,
> >
> > > I am trying to insert data in 2 tables from one form... I would like to
> be
> > > able to insert any number of rows or records in the subtable.
> >
> > > I build this test app (see attach)... All the work I did is mostly in
> > > /default/register.html where there is jQuery script that allow adding
> new
> > > city input and delete new city input...
> >
> > > I built it from scratch for Web2py inspired by :
> > >http://charlie.griefer.com/blog/index.cfm/2009/9/17/jQuery--Dynamical.
> ..
> >
> > > What should I do in register to allow the function to insert all the
> filled
> > > city clone field??
> >
> > > Next step will be adapted my script that it manage all the subform
> columns
> > > instead of only one.
> >
> > > Thanks.
> >
> > > Richard
>


Re: [web2py] Re: [off-topic] - Jquery Panels/dashboard Plugin

2011-01-19 Thread Richard Vézina
So usefull thread!!

Thanks guys

Richard

On Tue, Jan 18, 2011 at 11:03 PM, Anthony  wrote:

> On Tuesday, January 18, 2011 10:38:03 PM UTC-5, rochacbruno wrote:
>>
>> It has a 2.0 version http://www.trilancer.com/jpolite2/
>>
>
> Yeah, the version at http://www.web2py.com/jpolite is actually a port of
> the older JPolite to web2py, but it probably makes sense to work with the
> newer version (though development doesn't appear to be very active).
>


[web2py] Re: form / subform / adding row (field)...

2011-01-19 Thread mart
Excellent! je prends le train, direction MTL, a tous les quelques mois
pour me rendre au bureau (peut-etre un peu moins souvent l'hiver ;) )

SO, I have a question: Once, I use the button to add a field (which
does work well), what should be the expected back-end result? does one
of the tables get updated? or should a new table get generated based
on input type? How about a Field name? generic one name fits all (or
depends on type?)

Mart :)



On Jan 19, 9:12 am, Richard Vézina 
wrote:
> ;-) Originellement oui...
>
> I would tell you on the orther thread that I post this one... I will do it
> just for the one that fall on the orther thread so they could keep track...
>
> I continue today working on this.
>
> Richard
>
>
>
>
>
>
>
> On Wed, Jan 19, 2011 at 12:30 AM, mart  wrote:
> > Hey, es-tu de Montreal?
>
> > On Jan 18, 7:08 pm, Richard Vézina 
> > wrote:
> > > I forgot to paste :
>
> > > def register():
> > >     form=SQLFORM.factory(db.client, db.address, formstyle = 'divs') #,
> > > table_name='dummy_name')
> > >     if form.accepts(request.vars):
> > >         id = db.client.insert(**db.client._filter_fields(form.vars))
> > >         form.vars.client=id
> > >         id = db.address.insert(**db.address._filter_fields(form.vars))
> > >         response.flash='Thanks for filling the form'
> > >     return dict(form=form)
>
> > > What to do for what in red?
>
> > > I think _filter_fields is the key of the problem...
>
> > > I didn't have a look to it actually...
>
> > > Richard
>
> > > On Tue, Jan 18, 2011 at 7:00 PM, Richard Vézina <
> > ml.richard.vez...@gmail.com
>
> > > > wrote:
> > > > Hello Massimo,
>
> > > > I am trying to insert data in 2 tables from one form... I would like to
> > be
> > > > able to insert any number of rows or records in the subtable.
>
> > > > I build this test app (see attach)... All the work I did is mostly in
> > > > /default/register.html where there is jQuery script that allow adding
> > new
> > > > city input and delete new city input...
>
> > > > I built it from scratch for Web2py inspired by :
> > > >http://charlie.griefer.com/blog/index.cfm/2009/9/17/jQuery--Dynamical.
> > ..
>
> > > > What should I do in register to allow the function to insert all the
> > filled
> > > > city clone field??
>
> > > > Next step will be adapted my script that it manage all the subform
> > columns
> > > > instead of only one.
>
> > > > Thanks.
>
> > > > Richard


[web2py] Re: Long-running controllers

2011-01-19 Thread ae


On Jan 19, 9:17 am, Anthony  wrote:
> On Wednesday, January 19, 2011 8:18:25 AM UTC-5, ae wrote:
>
> > I have lots of users and when one thread takes a long time, some users
> > can keep accessing controller functions and some can't.  Once the long-
> > running controller finishes, everyone can access stuff again.
>
> Are you saying that when user A hits a long-running controller (action),
> that sometimes blocks user B (who is presumably using a different machine)
> from accessing the application? Is this just a thread starvation issue? I
> assume user B wouldn't be affected by user A unless there just aren't any
> available threads left to service B's request, no?

Possibly.  If you have many threads, then B is unlikely to be assigned
to the same thread as A and the behavior won't be exhibited.

Configure web2py with just two threads and open a few browsers using
different profiles (they each have to have unique cookies).  They can
be on different hosts or not (My office-mate and I each have a desktop
and a laptop--we tested this together).

As for thread starvation, I'd say no.  The host running web2py is an 8-
core machine that's mostly idle.  I've also tested this on my desktop
(4-core) which was also mostly idle.  Also, the 'blocking' in the long
running function is just a call to sleep() and in the production
environment it's a connections to other hosts that block; they return
small (<1k) strings.  Lastly, if it were thread starvation, then I
would expect that no user could do anything.  For users who /can/
access the app, performance is normal.

It's easy to test this (but once more: Rocket might be different).



[web2py] Re: [off-topic] - Jquery Panels/dashboard Plugin

2011-01-19 Thread mart
Yeah, installed it last night too (I had always wondered what that was
about, 'jPolite' - I thought it was for displaying images, because of
the image of it on appliances :)). I think this could be the best kept
secret... jpolite for pod like applications would be a great thing
(and now i feel like giving it a go)... reminds me of Flex and the use
of "pods" for user defined views -> we used this in my previous
employment for reporting purposes.

Thanks :)

On Jan 19, 9:27 am, Richard Vézina 
wrote:
> So usefull thread!!
>
> Thanks guys
>
> Richard
>
>
>
>
>
>
>
> On Tue, Jan 18, 2011 at 11:03 PM, Anthony  wrote:
> > On Tuesday, January 18, 2011 10:38:03 PM UTC-5, rochacbruno wrote:
>
> >> It has a 2.0 versionhttp://www.trilancer.com/jpolite2/
>
> > Yeah, the version athttp://www.web2py.com/jpoliteis actually a port of
> > the older JPolite to web2py, but it probably makes sense to work with the
> > newer version (though development doesn't appear to be very active).


[web2py] Re: Long-running controllers

2011-01-19 Thread Anthony
Hmm, this sounds contrary to what Massimo and Jonathan have been saying. 
>From their explanations, it sounds like user A should not be blocking user B 
(i.e., their requests should not be sharing a thread).
 
On Wednesday, January 19, 2011 9:50:35 AM UTC-5, ae wrote:

>
>
> On Jan 19, 9:17 am, Anthony  wrote: 
> > On Wednesday, January 19, 2011 8:18:25 AM UTC-5, ae wrote: 
> > 
> > > I have lots of users and when one thread takes a long time, some users 
> > > can keep accessing controller functions and some can't.  Once the long- 
>
> > > running controller finishes, everyone can access stuff again. 
> > 
> > Are you saying that when user A hits a long-running controller (action), 
> > that sometimes blocks user B (who is presumably using a different 
> machine) 
> > from accessing the application? Is this just a thread starvation issue? I 
>
> > assume user B wouldn't be affected by user A unless there just aren't any 
>
> > available threads left to service B's request, no? 
>
> Possibly.  If you have many threads, then B is unlikely to be assigned 
> to the same thread as A and the behavior won't be exhibited. 
>
> Configure web2py with just two threads and open a few browsers using 
> different profiles (they each have to have unique cookies).  They can 
> be on different hosts or not (My office-mate and I each have a desktop 
> and a laptop--we tested this together). 
>
> As for thread starvation, I'd say no.  The host running web2py is an 8- 
> core machine that's mostly idle.  I've also tested this on my desktop 
> (4-core) which was also mostly idle.  Also, the 'blocking' in the long 
> running function is just a call to sleep() and in the production 
> environment it's a connections to other hosts that block; they return 
> small (<1k) strings.  Lastly, if it were thread starvation, then I 
> would expect that no user could do anything.  For users who /can/ 
> access the app, performance is normal. 
>
> It's easy to test this (but once more: Rocket might be different). 
>
>

[web2py] Re: Long-running controllers

2011-01-19 Thread ae


On Jan 18, 11:21 pm, Anthony  wrote:
> I tried this (the session.forget() version), and sayjunk is still being
> blocked for 30 seconds while waiting for blockme to finish (only when in the
> same browser -- I can load sayjunk in a different browser, which starts a
> different session). Am I missing something?

Well, maybe not.  I just downloaded 1.91.6 and I couldn't replicate
the behavior.  We use 1.67.1 in production and what I tested on might
have been even older than that.


Re: [web2py] Re: Long-running controllers

2011-01-19 Thread Anthony

On Wednesday, January 19, 2011 1:35:09 AM UTC-5, Jonathan Lundell wrote: 
>
> Actually, there's a bug in the documentation (or else in Session). You have 
> to say: 
>
> session.forget(response) 
>
> or else the session doesn't get unlocked
>
There are at least four occurrences of session.forget() in the book, and one 
in the 'call' action in the default.py controller of the 'welcome' app. 
Should all of those be replaced with session.forget(response)? Is there any 
reason to use session.forget() with the default response=None (which sets 
session._forget=True but does not unlock the session file)? If not, maybe 
the default behavior of session.forget() itself should be changed.


Re: [web2py] Re: form / subform / adding row (field)...

2011-01-19 Thread Richard Vézina
For now only adding and removing city input. I clone city input retag
id='city' to id='city2' for the first clone and so on. I change all the id
attribute of other tag cloned like divs. I had a garbage can icon and make
it mouseover. That it for now.

Since I change the id of input to city2, city3 all those cloned input are
not consider by the register controller for now. I have to figure out how
_filter_fields works to modifying it (add regex hope it will work). Then I
would like the controller to add as many rows in the "subform" or table2
(address table) as there is cloned city input fields.

If I am not changing the id of input it will not be w3c html compliant, but
web2py will insert all the added input filled into city field of address
table like this :

|city1|city2|city3|etc|

Not bad but not normalized schema and possibly problematic if length of city
field is fixed or using to much space for nothing.

If you feel that you know how to modify register function I will be glad for
your help.

When it read, we could had a new recipe into the book ;-)

Richard



On Wed, Jan 19, 2011 at 9:48 AM, mart  wrote:

> Excellent! je prends le train, direction MTL, a tous les quelques mois
> pour me rendre au bureau (peut-etre un peu moins souvent l'hiver ;) )
>
> SO, I have a question: Once, I use the button to add a field (which
> does work well), what should be the expected back-end result? does one
> of the tables get updated? or should a new table get generated based
> on input type? How about a Field name? generic one name fits all (or
> depends on type?)
>
> Mart :)
>
>
>
> On Jan 19, 9:12 am, Richard Vézina 
> wrote:
> > ;-) Originellement oui...
> >
> > I would tell you on the orther thread that I post this one... I will do
> it
> > just for the one that fall on the orther thread so they could keep
> track...
> >
> > I continue today working on this.
> >
> > Richard
> >
> >
> >
> >
> >
> >
> >
> > On Wed, Jan 19, 2011 at 12:30 AM, mart  wrote:
> > > Hey, es-tu de Montreal?
> >
> > > On Jan 18, 7:08 pm, Richard Vézina 
> > > wrote:
> > > > I forgot to paste :
> >
> > > > def register():
> > > > form=SQLFORM.factory(db.client, db.address, formstyle = 'divs')
> #,
> > > > table_name='dummy_name')
> > > > if form.accepts(request.vars):
> > > > id = db.client.insert(**db.client._filter_fields(form.vars))
> > > > form.vars.client=id
> > > > id =
> db.address.insert(**db.address._filter_fields(form.vars))
> > > > response.flash='Thanks for filling the form'
> > > > return dict(form=form)
> >
> > > > What to do for what in red?
> >
> > > > I think _filter_fields is the key of the problem...
> >
> > > > I didn't have a look to it actually...
> >
> > > > Richard
> >
> > > > On Tue, Jan 18, 2011 at 7:00 PM, Richard Vézina <
> > > ml.richard.vez...@gmail.com
> >
> > > > > wrote:
> > > > > Hello Massimo,
> >
> > > > > I am trying to insert data in 2 tables from one form... I would
> like to
> > > be
> > > > > able to insert any number of rows or records in the subtable.
> >
> > > > > I build this test app (see attach)... All the work I did is mostly
> in
> > > > > /default/register.html where there is jQuery script that allow
> adding
> > > new
> > > > > city input and delete new city input...
> >
> > > > > I built it from scratch for Web2py inspired by :
> > > > >
> http://charlie.griefer.com/blog/index.cfm/2009/9/17/jQuery--Dynamical.
> > > ..
> >
> > > > > What should I do in register to allow the function to insert all
> the
> > > filled
> > > > > city clone field??
> >
> > > > > Next step will be adapted my script that it manage all the subform
> > > columns
> > > > > instead of only one.
> >
> > > > > Thanks.
> >
> > > > > Richard
>


Re: [web2py] Re: form / subform / adding row (field)...

2011-01-19 Thread Richard Vézina
If you move the script into the layout.html in the head it still works...
You can then remove the view /view/default/register.html_

So you get access to admin, request, session, response button to see what
going. You can see that city2 vars is store in session for example.

Richard

On Wed, Jan 19, 2011 at 10:17 AM, Richard Vézina <
ml.richard.vez...@gmail.com> wrote:

> For now only adding and removing city input. I clone city input retag
> id='city' to id='city2' for the first clone and so on. I change all the id
> attribute of other tag cloned like divs. I had a garbage can icon and make
> it mouseover. That it for now.
>
> Since I change the id of input to city2, city3 all those cloned input are
> not consider by the register controller for now. I have to figure out how
> _filter_fields works to modifying it (add regex hope it will work). Then I
> would like the controller to add as many rows in the "subform" or table2
> (address table) as there is cloned city input fields.
>
> If I am not changing the id of input it will not be w3c html compliant, but
> web2py will insert all the added input filled into city field of address
> table like this :
>
> |city1|city2|city3|etc|
>
> Not bad but not normalized schema and possibly problematic if length of
> city field is fixed or using to much space for nothing.
>
> If you feel that you know how to modify register function I will be glad
> for your help.
>
> When it read, we could had a new recipe into the book ;-)
>
> Richard
>
>
>
> On Wed, Jan 19, 2011 at 9:48 AM, mart  wrote:
>
>> Excellent! je prends le train, direction MTL, a tous les quelques mois
>> pour me rendre au bureau (peut-etre un peu moins souvent l'hiver ;) )
>>
>> SO, I have a question: Once, I use the button to add a field (which
>> does work well), what should be the expected back-end result? does one
>> of the tables get updated? or should a new table get generated based
>> on input type? How about a Field name? generic one name fits all (or
>> depends on type?)
>>
>> Mart :)
>>
>>
>>
>> On Jan 19, 9:12 am, Richard Vézina 
>> wrote:
>> > ;-) Originellement oui...
>> >
>> > I would tell you on the orther thread that I post this one... I will do
>> it
>> > just for the one that fall on the orther thread so they could keep
>> track...
>> >
>> > I continue today working on this.
>> >
>> > Richard
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > On Wed, Jan 19, 2011 at 12:30 AM, mart  wrote:
>> > > Hey, es-tu de Montreal?
>> >
>> > > On Jan 18, 7:08 pm, Richard Vézina 
>> > > wrote:
>> > > > I forgot to paste :
>> >
>> > > > def register():
>> > > > form=SQLFORM.factory(db.client, db.address, formstyle = 'divs')
>> #,
>> > > > table_name='dummy_name')
>> > > > if form.accepts(request.vars):
>> > > > id = db.client.insert(**db.client._filter_fields(form.vars))
>> > > > form.vars.client=id
>> > > > id =
>> db.address.insert(**db.address._filter_fields(form.vars))
>> > > > response.flash='Thanks for filling the form'
>> > > > return dict(form=form)
>> >
>> > > > What to do for what in red?
>> >
>> > > > I think _filter_fields is the key of the problem...
>> >
>> > > > I didn't have a look to it actually...
>> >
>> > > > Richard
>> >
>> > > > On Tue, Jan 18, 2011 at 7:00 PM, Richard Vézina <
>> > > ml.richard.vez...@gmail.com
>> >
>> > > > > wrote:
>> > > > > Hello Massimo,
>> >
>> > > > > I am trying to insert data in 2 tables from one form... I would
>> like to
>> > > be
>> > > > > able to insert any number of rows or records in the subtable.
>> >
>> > > > > I build this test app (see attach)... All the work I did is mostly
>> in
>> > > > > /default/register.html where there is jQuery script that allow
>> adding
>> > > new
>> > > > > city input and delete new city input...
>> >
>> > > > > I built it from scratch for Web2py inspired by :
>> > > > >
>> http://charlie.griefer.com/blog/index.cfm/2009/9/17/jQuery--Dynamical.
>> > > ..
>> >
>> > > > > What should I do in register to allow the function to insert all
>> the
>> > > filled
>> > > > > city clone field??
>> >
>> > > > > Next step will be adapted my script that it manage all the subform
>> > > columns
>> > > > > instead of only one.
>> >
>> > > > > Thanks.
>> >
>> > > > > Richard
>>
>
>


[web2py] Re: social network idea

2011-01-19 Thread Anthony
On Wednesday, January 19, 2011 6:54:05 AM UTC-5, blackthorne wrote: 
>
> Oddly enough, I can't find a good code snippet network. 
> GitHub and alikes made a great step with code sharing for full 
> projects. You can search for projects not code snippets. 
> There are many snippet managers that help you managing your snippets. 
> Your code snippets. 
> There isn't much of a link between the previous two. 
>
> A snippet manager that also allows to search for snippets in others 
> code. I believe that there is room for success here for someone able 
> to do a cross-platform tool combining the capabilities to manage and 
> search/ 
> share code and a good integration. This is a very active minority made 
> of programmers that use their own tools and consider functionality 
> over the most. There is technology for this, a public XML-RPC API, a 
> website and some plugins for main IDE's. I also believe this would be 
> great for ourselves and for web2py visibility if this website used it. 
>
> Imagine writing your code, find a problem you never solved before and, 
> with minimal effort be able to search for very specific code samples 
> that you can use to learn and even apply when appropriate, always 
> without leaving your Emacs... 
>
 
Cool idea. Not exactly what you describe, but maybe a step in the right 
direction: http://nullege.com/
 


[web2py] keepvalues=True and _type='reset'

2011-01-19 Thread annet
To temporarily solve the problem described in this post I added
keepvalues=True, now when the records aren't inserted I just submit
the form again, which somehow works.

However, this causes the reset button to no longer work:

def create_form():
response.view='form.html'
form=SQLFORM.factory(
Field(..),
Field()))
form[0].insert(...)

form[0][-1][1].append(INPUT(_type='reset',_value='Reset'))
if form.accepts(request.vars,session,keepvalues=True):
...
return dict(form=form)


How to I solve this problem?


Kind regards,

Annet


[web2py] shell and Web interface at the same time

2011-01-19 Thread Richard Vézina
Hello,

Try to interact in shell and in the browser at the same time to test form
input... Is it possible to start web2py in both mode at the same time??

Or is there a way to insert form input in shell mode?

Thanks

Richard


[web2py] Re: WARNING:root:failure to stat applications

2011-01-19 Thread Massimo Di Pierro
Please upgrade. 1.91.4 has known bugs. If you still have the problem,
we will look furtherinot this.

On Jan 18, 9:59 pm, Rupesh Pradhan  wrote:
> My Computer Configuration:
> CPU: Intel
> Motheboard: ASUS
> OS: Windows XP Profession, SP2
>
> Web2Py version: 1.91.4 (2010-12-22)
>
> Why am I getting this error?
>
> WARNING:root:failure to stat applications\admin\sessions\127.0.0.1-
> f6f76cfb-49b1-4b04-af6b-f0fae01c7d5d: expected a character buffer
> object
>
> When I leave the application alone for sometime i.e. when I am not
> actively using it, the dialog box reporting that an error has occurred
> pops up.
>
> The complete error log since epoch is given below for reference:
> --- 
> --
> ERROR:Rocket.Errors.ThreadPool:Socket 192.168.0.1:8000 in use by other
> process and it won't share.
> CRITICAL:Rocket.Errors.ThreadPool:No interfaces to listen
> on...closing.
> ERROR:Rocket.Errors.ThreadPool:Socket 192.168.0.1:8000 in use by other
> process and it won't share.
> CRITICAL:Rocket.Errors.ThreadPool:No interfaces to listen
> on...closing.
> ERROR:Rocket.Errors.ThreadPool:Socket 192.168.0.1:8000 in use by other
> process and it won't share.
> CRITICAL:Rocket.Errors.ThreadPool:No interfaces to listen
> on...closing.
> WARNING:root:failure to stat applications\admin\sessions
> \127-0-0-1-9591bf07-ecb6-415b-a56b-d9fbc9a115b1: expected a character
> buffer object
> WARNING:root:failure to stat applications\admin\sessions\127-0-0-1-
> b25a988f-9df3-4451-9bf6-8cefdbec438b: expected a character buffer
> object
> WARNING:root:failure to stat applications\admin\sessions
> \127.0.0.1-4028ed2f-4e8b-4d89-a428-060c3f4d4624: expected a character
> buffer object
> WARNING:root:failure to stat applications\admin\sessions\127.0.0.1-
> a7eeb5c4-ac61-4cbd-b2f6-5c9b348f5052: expected a character buffer
> object
> Unhandled exception in thread started by  HttpServer.start of >
> Traceback (most recent call last):
>   File "gluon/main.py", line 727, in start
>   File "gluon/rocket.py", line 419, in start
>   File "gluon/rocket.py", line 431, in stop
>   File "gluon/rocket.py", line 712, in stop
> RuntimeError: Set changed size during iteration
> WARNING:root:failure to stat applications\admin\sessions\127.0.0.1-
> a14eda27-98c2-47cd-940f-975564236afd: expected a character buffer
> object
> WARNING:root:failure to stat applications\admin\sessions\127.0.0.1-
> a7eeb5c4-ac61-4cbd-b2f6-5c9b348f5052: expected a character buffer
> object
> WARNING:root:failure to stat applications\admin\sessions\127.0.0.1-
> a9476b99-b737-42eb-8220-d5afe539117c: expected a character buffer
> object
> WARNING:root:failure to stat applications\admin\sessions\127.0.0.1-
> dd2af7f2-5851-4ab9-bb5b-b280f73fe1b7: expected a character buffer
> object
> WARNING:root:failure to stat applications\admin\sessions\127.0.0.1-
> f6f76cfb-49b1-4b04-af6b-f0fae01c7d5d: expected a character buffer
> object
> WARNING:root:failure to stat applications\admin\sessions\127.0.0.1-
> a14eda27-98c2-47cd-940f-975564236afd: expected a character buffer
> object
> WARNING:root:failure to stat applications\admin\sessions\127.0.0.1-
> a7eeb5c4-ac61-4cbd-b2f6-5c9b348f5052: expected a character buffer
> object
> WARNING:root:failure to stat applications\admin\sessions\127.0.0.1-
> a9476b99-b737-42eb-8220-d5afe539117c: expected a character buffer
> object
> WARNING:root:failure to stat applications\admin\sessions\127.0.0.1-
> d4843b6d-dffb-40e8-a3bd-5f527212e890: expected a character buffer
> object
> WARNING:root:failure to stat applications\admin\sessions\127.0.0.1-
> dd2af7f2-5851-4ab9-bb5b-b280f73fe1b7: expected a character buffer
> object
> WARNING:root:failure to stat applications\admin\sessions\127.0.0.1-
> f6f76cfb-49b1-4b04-af6b-f0fae01c7d5d: expected a character buffer
> object
> WARNING:root:failure to stat applications\admin\sessions\127.0.0.1-
> a14eda27-98c2-47cd-940f-975564236afd: expected a character buffer
> object
> WARNING:root:failure to stat applications\admin\sessions\127.0.0.1-
> a7eeb5c4-ac61-4cbd-b2f6-5c9b348f5052: expected a character buffer
> object
> WARNING:root:failure to stat applications\admin\sessions\127.0.0.1-
> a9476b99-b737-42eb-8220-d5afe539117c: expected a character buffer
> object
> WARNING:root:failure to stat applications\admin\sessions\127.0.0.1-
> d4843b6d-dffb-40e8-a3bd-5f527212e890: expected a character buffer
> object
> WARNING:root:failure to stat applications\admin\sessions\127.0.0.1-
> dd2af7f2-5851-4ab9-bb5b-b280f73fe1b7: expected a character buffer
> object
> WARNING:root:failure to stat applications\admin\sessions\127.0.0.1-
> f6f76cfb-49b1-4b04-af6b-f0fae01c7d5d: expected a character buffer
> object
> --- 
> --- 
> ---


[web2py] Re: Shell & controllers & views

2011-01-19 Thread Massimo Di Pierro
No. You can only access the models.

On Jan 19, 12:31 am, walter  wrote:
> Question about a shell. Can I interact to controllers and views as
> easy as a DB? If it is true, how?


[web2py] Re: - Jquery Panels/dashboard Plugin

2011-01-19 Thread Massimo Di Pierro
Mind that is a veyr old app that uses something called jDiv which
later evolved into LOAD. It should be rewritten using jpolite 2 and
LOAD.

On Jan 18, 6:21 pm, Anthony  wrote:
> Probably not quite what you're looking for, but maybe this could 
> help:http://www.web2py.com/jpolite
>
>
>
>
>
>
>
> On Tuesday, January 18, 2011 6:52:31 PM UTC-5, rochacbruno wrote:
> > Hi,
>
> > I am looking for a panel plugin for Jquery.
>
> > I need to build a page with panels like thathttp://diogobaeder.com.br/and
> > like the one we see in htp://google.com/ig
>
> > Is there anybody who knows a good jquery plugin for doing that?
>
> >  (I tried Jquery Dashboard plugin, but it is JSon based, I need to use
> > LOAD() to load the content for each panel)
>
> > --
> > Bruno Rocha
> >http://about.me/rochacbruno/bio


[web2py] Re: shell and Web interface at the same time

2011-01-19 Thread Massimo Di Pierro
Both may lock the DB in sqlite. That is the only problem I can think
of.

On Jan 19, 9:45 am, Richard Vézina 
wrote:
> Hello,
>
> Try to interact in shell and in the browser at the same time to test form
> input... Is it possible to start web2py in both mode at the same time??
>
> Or is there a way to insert form input in shell mode?
>
> Thanks
>
> Richard


Re: [web2py] Re: shell and Web interface at the same time

2011-01-19 Thread Richard Vézina
Can't find the exast bash command to do it. (I have postgres)

With :
python web2py.py -a 'asdf' -i 127.0.0.1 -p 8001 -S appname -M auto'

I got the ipython, but when I go to 127.0.0.1:8001 nothing...

Richard


On Wed, Jan 19, 2011 at 11:03 AM, Massimo Di Pierro <
massimo.dipie...@gmail.com> wrote:

> Both may lock the DB in sqlite. That is the only problem I can think
> of.
>
> On Jan 19, 9:45 am, Richard Vézina 
> wrote:
> > Hello,
> >
> > Try to interact in shell and in the browser at the same time to test form
> > input... Is it possible to start web2py in both mode at the same time??
> >
> > Or is there a way to insert form input in shell mode?
> >
> > Thanks
> >
> > Richard
>


Re: [web2py] Re: shell and Web interface at the same time

2011-01-19 Thread Bruno Rocha
Richard,

python web2py.py -a 'asdf' -i 127.0.0.1 -p 8001 -S appname -M auto'

Starts only web2py interactive shell mode, not the webserver.

You have to open 2 consoles

in the first you do:
python web2py.py -S appname -M -P

in second you do:
python web2py.py -a 'asdf' -i 127.0.0.1 -p 8001'



Bruno Rocha
http://about.me/rochacbruno/bio


Re: [web2py] Re: Long-running controllers

2011-01-19 Thread Jonathan Lundell
On Jan 19, 2011, at 6:50 AM, ae wrote:
> 
> 
> 
> On Jan 19, 9:17 am, Anthony  wrote:
>> On Wednesday, January 19, 2011 8:18:25 AM UTC-5, ae wrote:
>> 
>>> I have lots of users and when one thread takes a long time, some users
>>> can keep accessing controller functions and some can't.  Once the long-
>>> running controller finishes, everyone can access stuff again.
>> 
>> Are you saying that when user A hits a long-running controller (action),
>> that sometimes blocks user B (who is presumably using a different machine)
>> from accessing the application? Is this just a thread starvation issue? I
>> assume user B wouldn't be affected by user A unless there just aren't any
>> available threads left to service B's request, no?
> 
> Possibly.  If you have many threads, then B is unlikely to be assigned
> to the same thread as A and the behavior won't be exhibited.
> 
> Configure web2py with just two threads and open a few browsers using
> different profiles (they each have to have unique cookies).  They can
> be on different hosts or not (My office-mate and I each have a desktop
> and a laptop--we tested this together).
> 
> As for thread starvation, I'd say no.  The host running web2py is an 8-
> core machine that's mostly idle.  I've also tested this on my desktop
> (4-core) which was also mostly idle.  Also, the 'blocking' in the long
> running function is just a call to sleep() and in the production
> environment it's a connections to other hosts that block; they return
> small (<1k) strings.  Lastly, if it were thread starvation, then I
> would expect that no user could do anything.  For users who /can/
> access the app, performance is normal.
> 
> It's easy to test this (but once more: Rocket might be different).
> 

When a request is received, a thread is created (or recycled from a thread 
pool) to handle it. That thread is dedicated to that request for its entire 
life cycle, and is destroyed or returned to the pool afterward. The request is 
associated with its session by means of a cookie. The session is locked for the 
duration of the request (or until you call session.forget(response) to release 
the lock), so any new request with the same cookie/session will block until the 
session is released.

Re: [web2py] web2py website and 404's

2011-01-19 Thread Jonathan Lundell
On Jan 19, 2011, at 3:55 AM, Albert Abril wrote:
> Just a suggestion.
> 
> When I an incorrect url, for example:
> http://web2py.com/layout  (instead of http://web2py.com/layouts)
> 
> ...appears an "invalid controller" error, as it's expected.
> 
> What if it instead is shown a nicer 404? 
> 

Right now it's a 400 error: bad request. It probably *should* be a 404, though 
the "invalid controller" text is useful (I think) in explaining where the URL 
went wrong. You can manage this yourself, to some extent anyway, through 
routes.py.

Re: [web2py] Re: shell and Web interface at the same time

2011-01-19 Thread Richard Vézina
Then I will be able to request.vars?

I go test.

Richard

On Wed, Jan 19, 2011 at 11:37 AM, Bruno Rocha  wrote:

> Richard,
>
> python web2py.py -a 'asdf' -i 127.0.0.1 -p 8001 -S appname -M auto'
>
> Starts only web2py interactive shell mode, not the webserver.
>
> You have to open 2 consoles
>
> in the first you do:
> python web2py.py -S appname -M -P
>
> in second you do:
> python web2py.py -a 'asdf' -i 127.0.0.1 -p 8001'
>
>
>
> Bruno Rocha
> http://about.me/rochacbruno/bio
>


Re: [web2py] Re: Shell & controllers & views

2011-01-19 Thread Bruno Rocha
2011/1/19 Massimo Di Pierro 

> No. You can only access the models.


I wonder if it is possible to start web2py in Shell mode, execute a
controller under the web2py environment.
inspect the controllers 'return' or use template.py to evaluate a view file
passing the controller return as argument.

is there something like that?


$python web2py.py -S myapp -M -P
>>> db.tables
['mytable']
>>> my_return = execfile(/controllers/controller.py)
>>> print my_return['someobject']
>>> from gluon.template import *
>>> print template.parse('/views/controller.html',response._vars=my_return)
'.



I guess I saw something like this in web2py_test_runner.

If something like that could be possible, this will be easy to UnitTest
web2py controllers and views.


[web2py] plugin_wiki widget jqgrid: colnames or columns?

2011-01-19 Thread blackthorne
The way you define the column names in the Jqgrid plugin is done,
according to the book, with the "columns" attribute is a list of
columns names to be displayed. However, in the plugin_wiki widget
builder interface that is done with the attribute "colnames".
In the code plugin_wiki controller, the used word seems to be
"columns" as well.

That said, I also couldn't make it with columns:

``
name: jqgrid
table: plugin_wiki_page
fields: id,slug,description
columns: title,slug,description
width: 500
col_width: [100,80,320]
height: 300
``:widget

Failed with:
traceback:
TypeError: jqgrid() got an unexpected keyword argument 'columns'

Then I tried "colnames":
And I got a dialog window with the message:
"Length of colNames <> colModel!"


Re: [web2py] Re: shell and Web interface at the same time

2011-01-19 Thread Richard Vézina
Nop!

In [2]: request.vars
Out[2]: 


Samething with plain python shell (-P option)

Richard

On Wed, Jan 19, 2011 at 11:46 AM, Richard Vézina <
ml.richard.vez...@gmail.com> wrote:

> Then I will be able to request.vars?
>
> I go test.
>
> Richard
>
>
> On Wed, Jan 19, 2011 at 11:37 AM, Bruno Rocha wrote:
>
>> Richard,
>>
>> python web2py.py -a 'asdf' -i 127.0.0.1 -p 8001 -S appname -M auto'
>>
>> Starts only web2py interactive shell mode, not the webserver.
>>
>> You have to open 2 consoles
>>
>> in the first you do:
>> python web2py.py -S appname -M -P
>>
>> in second you do:
>> python web2py.py -a 'asdf' -i 127.0.0.1 -p 8001'
>>
>>
>>
>> Bruno Rocha
>> http://about.me/rochacbruno/bio
>>
>
>


Re: [web2py] Re: Shell & controllers & views

2011-01-19 Thread howesc
hmmm, something say like:


def unittests():
"""
test the ability to run unittests
"""
import os
import sys
import glob
import cStringIO

from gluon.shell import env

#save stdout so we can capture data and reset it.
stdout = sys.stdout
stderr = sys.stderr

#get a list of the modules to test
cdir = os.path.join('applications', request.application, 'tests')
if not os.path.isdir(cdir):
die(errmsg)
files = glob.glob(os.path.join(cdir, '*.py'))


html = ''
test_count = 0
pass_count = 0
fail_count = 0
for testfile in files:
test_count += 1
html += 'Running Test "%s.py" ... done.\n' % testfile
# Reload environment before each test.
globs = env(request.application, c='default', f='index',
import_models=True, extra_request={'test_db':True})

sys.stdout = cStringIO.StringIO()
execfile(testfile, globs)
report = sys.stdout.getvalue().strip()
if report.find('FAIL') >= 0:
fail_count += 1
html += 'FAILED\n'
html += CODE(report, language='web2py', \
 link='/examples/global/vars/').xml()
else:
pass_count += 1
html += 'PASSED\n'


sys.stdout = stdout

return dict(html=XML(html),
test_count = test_count,
pass_count = pass_count,
fail_count = fail_count)

I'm in the process of creating some functions that will allow me to run some 
doctests and unittests from the browser on google app engine.  the above is 
the start of my method for unit testing.  i think it basically does what 
bruno suggests, but just not in an interactive shell environment.

i'll post a slice when i get my testing tools together.

christian


[web2py] Re: web2py website and 404's

2011-01-19 Thread VP
It's definitely nicer (more professional) to have a customized page
for invalid request.


Re: [web2py] Re: Long-running controllers

2011-01-19 Thread ron_m
If the response is left off the session.forget() parameter list it defaults 
to None. The end result then is the session._forget state variable is set 
True but the session file is not unlocked in the _unlock function. This 
would enhance performance by bypassing the writing of the session file at 
the end of the request-response cycle when the session state is unchanged 
but won't release the lock to let other requests proceed on that session. I 
could see this as a possible use of session.forget(..) so it looks like a 
documentation issue.



Re: [web2py] Re: Long-running controllers

2011-01-19 Thread Anthony
So, I guess the question is, what should the book (and the 'call' function 
in the scaffolding app) be recommending, session.forget() 
or session.forget(response)? At the very least, the difference between the 
two should be explained in the book. 

On Wednesday, January 19, 2011 1:26:06 PM UTC-5, ron_m wrote:

> If the response is left off the session.forget() parameter list it defaults 
> to None. The end result then is the session._forget state variable is set 
> True but the session file is not unlocked in the _unlock function. This 
> would enhance performance by bypassing the writing of the session file at 
> the end of the request-response cycle when the session state is unchanged 
> but won't release the lock to let other requests proceed on that session. I 
> could see this as a possible use of session.forget(..) so it looks like a 
> documentation issue.
>
>

[web2py] Re: WARNING:root:failure to stat applications

2011-01-19 Thread Rupesh Pradhan
Ok.
Thanks for the response.


On Jan 19, 8:59 pm, Massimo Di Pierro 
wrote:
> Please upgrade. 1.91.4 has known bugs. If you still have the problem,
> we will look furtherinot this.
>
> On Jan 18, 9:59 pm, Rupesh Pradhan  wrote:
>
>
>
> > My Computer Configuration:
> > CPU: Intel
> > Motheboard: ASUS
> > OS: Windows XP Profession, SP2
>
> > Web2Py version: 1.91.4 (2010-12-22)
>
> > Why am I getting this error?
>
> > WARNING:root:failure to stat applications\admin\sessions\127.0.0.1-
> > f6f76cfb-49b1-4b04-af6b-f0fae01c7d5d: expected a character buffer
> > object
>
> > When I leave the application alone for sometime i.e. when I am not
> > actively using it, the dialog box reporting that an error has occurred
> > pops up.
>
> > The complete error log since epoch is given below for reference:
> > --- 
> > --
> > ERROR:Rocket.Errors.ThreadPool:Socket 192.168.0.1:8000 in use by other
> > process and it won't share.
> > CRITICAL:Rocket.Errors.ThreadPool:No interfaces to listen
> > on...closing.
> > ERROR:Rocket.Errors.ThreadPool:Socket 192.168.0.1:8000 in use by other
> > process and it won't share.
> > CRITICAL:Rocket.Errors.ThreadPool:No interfaces to listen
> > on...closing.
> > ERROR:Rocket.Errors.ThreadPool:Socket 192.168.0.1:8000 in use by other
> > process and it won't share.
> > CRITICAL:Rocket.Errors.ThreadPool:No interfaces to listen
> > on...closing.
> > WARNING:root:failure to stat applications\admin\sessions
> > \127-0-0-1-9591bf07-ecb6-415b-a56b-d9fbc9a115b1: expected a character
> > buffer object
> > WARNING:root:failure to stat applications\admin\sessions\127-0-0-1-
> > b25a988f-9df3-4451-9bf6-8cefdbec438b: expected a character buffer
> > object
> > WARNING:root:failure to stat applications\admin\sessions
> > \127.0.0.1-4028ed2f-4e8b-4d89-a428-060c3f4d4624: expected a character
> > buffer object
> > WARNING:root:failure to stat applications\admin\sessions\127.0.0.1-
> > a7eeb5c4-ac61-4cbd-b2f6-5c9b348f5052: expected a character buffer
> > object
> > Unhandled exception in thread started by  > HttpServer.start of >
> > Traceback (most recent call last):
> >   File "gluon/main.py", line 727, in start
> >   File "gluon/rocket.py", line 419, in start
> >   File "gluon/rocket.py", line 431, in stop
> >   File "gluon/rocket.py", line 712, in stop
> > RuntimeError: Set changed size during iteration
> > WARNING:root:failure to stat applications\admin\sessions\127.0.0.1-
> > a14eda27-98c2-47cd-940f-975564236afd: expected a character buffer
> > object
> > WARNING:root:failure to stat applications\admin\sessions\127.0.0.1-
> > a7eeb5c4-ac61-4cbd-b2f6-5c9b348f5052: expected a character buffer
> > object
> > WARNING:root:failure to stat applications\admin\sessions\127.0.0.1-
> > a9476b99-b737-42eb-8220-d5afe539117c: expected a character buffer
> > object
> > WARNING:root:failure to stat applications\admin\sessions\127.0.0.1-
> > dd2af7f2-5851-4ab9-bb5b-b280f73fe1b7: expected a character buffer
> > object
> > WARNING:root:failure to stat applications\admin\sessions\127.0.0.1-
> > f6f76cfb-49b1-4b04-af6b-f0fae01c7d5d: expected a character buffer
> > object
> > WARNING:root:failure to stat applications\admin\sessions\127.0.0.1-
> > a14eda27-98c2-47cd-940f-975564236afd: expected a character buffer
> > object
> > WARNING:root:failure to stat applications\admin\sessions\127.0.0.1-
> > a7eeb5c4-ac61-4cbd-b2f6-5c9b348f5052: expected a character buffer
> > object
> > WARNING:root:failure to stat applications\admin\sessions\127.0.0.1-
> > a9476b99-b737-42eb-8220-d5afe539117c: expected a character buffer
> > object
> > WARNING:root:failure to stat applications\admin\sessions\127.0.0.1-
> > d4843b6d-dffb-40e8-a3bd-5f527212e890: expected a character buffer
> > object
> > WARNING:root:failure to stat applications\admin\sessions\127.0.0.1-
> > dd2af7f2-5851-4ab9-bb5b-b280f73fe1b7: expected a character buffer
> > object
> > WARNING:root:failure to stat applications\admin\sessions\127.0.0.1-
> > f6f76cfb-49b1-4b04-af6b-f0fae01c7d5d: expected a character buffer
> > object
> > WARNING:root:failure to stat applications\admin\sessions\127.0.0.1-
> > a14eda27-98c2-47cd-940f-975564236afd: expected a character buffer
> > object
> > WARNING:root:failure to stat applications\admin\sessions\127.0.0.1-
> > a7eeb5c4-ac61-4cbd-b2f6-5c9b348f5052: expected a character buffer
> > object
> > WARNING:root:failure to stat applications\admin\sessions\127.0.0.1-
> > a9476b99-b737-42eb-8220-d5afe539117c: expected a character buffer
> > object
> > WARNING:root:failure to stat applications\admin\sessions\127.0.0.1-
> > d4843b6d-dffb-40e8-a3bd-5f527212e890: expected a character buffer
> > object
> > WARNING:root:failure to stat applications\admin\sessions\127.0.0.1-
> > dd2af7f2-5851-4ab9-bb5b-b280f73fe1b7: expected a character buffer
> > object
> > WARNING:root:failure to stat applications\admin\sessions\127.0.0

Re: [web2py] Re: Long-running controllers

2011-01-19 Thread Jonathan Lundell
On Jan 19, 2011, at 10:26 AM, ron_m wrote:
> If the response is left off the session.forget() parameter list it defaults 
> to None. The end result then is the session._forget state variable is set 
> True but the session file is not unlocked in the _unlock function. This would 
> enhance performance by bypassing the writing of the session file at the end 
> of the request-response cycle when the session state is unchanged but won't 
> release the lock to let other requests proceed on that session. I could see 
> this as a possible use of session.forget(..) so it looks like a documentation 
> issue.

There's another odd behavior. If you call session.forget(response), then 
_unlock will eventually be called twice (once for forget, once in the early-out 
path of _try_store_on_disk). 

def _unlock(self, response):
if response and response.session_file:
try:
portalocker.unlock(response.session_file)
except: ### this should never happen but happens in Windows
pass

Perhaps that's the reason for the "should never happen" exception?

Possible fix:

def _unlock(self, response):
if response and response.session_file:
try:
portalocker.unlock(response.session_file)
except: ### this should never happen but happens in Windows
pass
response.session_file.close()
del response.session_file

The logic is subtle, because Session defers the creation of the original 
session file until _try_store_on_disk, so if you forget() a session before the 
file is created, it never gets created. I think this logic works, though, 
assuming that a double unlock happens only because of forget.



[web2py] Re: Apache, Wsgi problem

2011-01-19 Thread VP
UPDATE:  I am able to reproduce this "Premature end of script headers:
wsgihandler.py" error with a slightly modified app based on the image
blog in the web2py book.   I modified it so that images are shown in
the index page, instead of having just the titles listed.

Testing using: ab -kc 100 -t 20 https://domain.com/imageblog/default/index/

If I am simply doing this, there's no error.  BUT when I was running
this test, while simultaneously browsing the website, clicking on
images, etc., then the error appeared, consistently.

Monitoring available RAM while running this test showed system RAM
peeked at about 500MB, still a few hundreds MB available. This is on
the same server as the other app.  VPS. 768MB RAM.  1GB RAM
Burstable.   About 129 apache2 processes running and 11,000 files
openning.

sudo ps aux | grep apache2 | wc
1291675   11847

sudo lsof | wc
  10982  106870 1313126


=
Here's a typical Apache Bench result:

Server Software:Apache/2.2.9
Server Port:443
SSL/TLS Protocol:   TLSv1/SSLv3,DHE-RSA-AES256-SHA,1024,256

Document Path:  /imageblog/default/index/
Document Length:13130 bytes

Concurrency Level:  100
Time taken for tests:   20.004 seconds
Complete requests:  588
Failed requests:15
   (Connect: 0, Receive: 0, Length: 15, Exceptions: 0)
Write errors:   0
Non-2xx responses:  15
Keep-Alive requests:573
Total transferred:  7875930 bytes
HTML transferred:   7564607 bytes
Requests per second:29.39 [#/sec] (mean)
Time per request:   3401.991 [ms] (mean)
Time per request:   34.020 [ms] (mean, across all concurrent
requests)
Transfer rate:  384.50 [Kbytes/sec] received

Connection Times (ms)
  min  mean[+/-sd] median   max
Connect:0  912 2146.5  07265
Processing:86 2234 1303.3   27814427
Waiting:   85 2136 1281.0   27594316
Total: 86 3146 2410.6   3017   10478

Percentage of the requests served within a certain time (ms)
  50%   3017
  66%   3222
  75%   3939
  80%   4029
  90%   7089
  95%   9409
  98%  10098
  99%  10223
 100%  10478 (longest request)

=

Relevant excerpt of db.py:

db = DAL('postgres://username:password@localhost:5432/imageblog',
pool_size=20)


=
Model:

db.define_table('image',
   Field('title'),
   Field('file', 'upload'))

db.define_table('comment',
   Field('image_id', db.image),
   Field('author'),
   Field('email'),
   Field('body', 'text'))

db.image.title.requires = IS_NOT_IN_DB(db, db.image.title)
db.comment.image_id.requires = IS_IN_DB(db, db.image.id, '%(title)s')
db.comment.author.requires = IS_NOT_EMPTY()
db.comment.email.requires = IS_EMAIL()
db.comment.body.requires = IS_NOT_EMPTY()

=
Controller:

def index():
images = db().select(db.image.ALL, orderby=db.image.title)
return dict(images=images)

@auth.requires_login()
def add():
form = crud.create(db.image, next = URL('index'))
return dict(form=form)

def show():
image = db(db.image.id==request.args(0)).select().first()
form = SQLFORM(db.comment)
form.vars.image_id = image.id
if form.accepts(request.vars, session):
response.flash = 'your comment is posted'
comments = db(db.comment.image_id==image.id).select()
return dict(image=image, comments=comments, form=form)

def user():
"""
exposes:
http:///[app]/default/user/login
http:///[app]/default/user/logout
http:///[app]/default/user/register
http:///[app]/default/user/profile
http:///[app]/default/user/retrieve_password
http:///[app]/default/user/change_password
use @auth.requires_login()
@auth.requires_membership('group name')
@auth.requires_permission('read','table name',record_id)
to decorate functions that need access control
"""
return dict(form=auth())


def download():
"""
allows downloading of uploaded files
http:///[app]/default/download/[filename]
"""
return response.download(request,db)


def call():
"""
exposes services. for example:
http:///[app]/default/call/jsonrpc
decorate with @services.jsonrpc the functions to expose
supports xml, json, xmlrpc, jsonrpc, amfrpc, rss, csv
"""
session.forget()
return service()


=
View (index.html)

{{extend 'layout.html'}}
Current Images

{{for image in images:}}

{{=A(image.title,
_href=URL("show", args=image.id))}}



{{pass}}

=

Apache's site-enabled/000-default:


  WSGIDaemonProcess web2py user=username group=username \
   display-name=%{GROUP}
  WSGIProcessGroup web2py
  WSGIScriptAlias / /home/username/web2py/wsgihandler.py

  Alias /awstats-ic

Re: [web2py] Re: Long-running controllers

2011-01-19 Thread ron_m
I remember session.forget() documented as a performance enhancement - no 
plans to alter session on this call, do this to save the write. I think this 
would be the most common use. Adding the response parameter to unlock the 
session file is only required if there is a need for concurrency in the same 
session. Normally this would apply to a user using more than one 
tab/window/browser from the same machine.

I have not explored what happens when you have multiple users behind a NAT 
box because to the server they would all appear to be using the same IP 
address. I need to study up on what causes the server to use a new session.


Re: [web2py] Re: Long-running controllers

2011-01-19 Thread Jonathan Lundell
On Jan 19, 2011, at 10:32 AM, Anthony wrote:
> So, I guess the question is, what should the book (and the 'call' function in 
> the scaffolding app) be recommending, session.forget() or 
> session.forget(response)? At the very least, the difference between the two 
> should be explained in the book. 

I can't think of a good use case for session.forget() (as opposed to 
session.forget(response)). Ron is right that it would eliminate the session 
file write, but that's pretty negligible in the overall scheme of things; I 
doubt it's worth supporting, let alone documenting. 

> 
> On Wednesday, January 19, 2011 1:26:06 PM UTC-5, ron_m wrote:
> If the response is left off the session.forget() parameter list it defaults 
> to None. The end result then is the session._forget state variable is set 
> True but the session file is not unlocked in the _unlock function. This would 
> enhance performance by bypassing the writing of the session file at the end 
> of the request-response cycle when the session state is unchanged but won't 
> release the lock to let other requests proceed on that session. I could see 
> this as a possible use of session.forget(..) so it looks like a documentation 
> issue.
> 




Re: [web2py] Re: Long-running controllers

2011-01-19 Thread ron_m
I saw that too last night but it was late. It would be better to set 
response.session_file to None which will force a file close since the file 
object goes out of scope. Adding a del in _unlock will cause AttributeError 
in the _try_store_on_disk when the request-response cycle is finishing up.


[web2py] Re: Apache, Wsgi problem

2011-01-19 Thread VP
What is curious is that RAM is still available, with this error.
Monitoring CPU (using top) shows CPU % is about 70% for apache2 (70%
is probably capped by my VPS host, given to each VPS slice).

And this occurs for a very simple app.  I hope Massimo or someone else
can reproduce this error with this app.   Note that while testing with
ab, you might have to browse the site, clicking on images, etc.
Otherwise, ab just it the same domain name repeatedly.


[web2py] Re: Apache, Wsgi problem

2011-01-19 Thread VP
I forgot to mention that in this imageblog app, I only have 10 images,
and no comment.  I.e. a very small database.

Here are the 10 images:

http://imgur.com/u6gwul&kJNwj&DsjQx&HIIN9&9AqEI&I5Pvh&1gxag&EcoJr&u2ucY&3583C


Re: [web2py] Re: Long-running controllers

2011-01-19 Thread ron_m
It would be better to set response.session_file to None in _unlock because 
the second _unlock call will generate an AttributeError when testing for 
response.session_file at the top of _unlock.


Re: [web2py] Re: Long-running controllers

2011-01-19 Thread Jonathan Lundell
On Jan 19, 2011, at 10:52 AM, ron_m wrote:
> I saw that too last night but it was late. It would be better to set 
> response.session_file to None which will force a file close since the file 
> object goes out of scope. Adding a del in _unlock will cause AttributeError 
> in the _try_store_on_disk when the request-response cycle is finishing up.

In practice, I don't think so, because the only reason this would happen would 
be through session.forget(), and _try_store_on_disk would never get that far. 
It wouldn't be very robust logic, though, I agree.

If we set response.session_file to None, we'd have to be careful when testing 
it, since session is Storage, so session.session_file is None even if it's not 
defined. We could set it to False, allowing an 'is False' test.

The del (or = None) could be conditional on self._forget. That'd help, because 
it'd guarantee that _try_store_on_disk would return.

   def forget(self, response=None):
self._forget = True
self._unlock(response)

   def _unlock(self, response):
   if response and response.session_file:
   try:
   portalocker.unlock(response.session_file)
   except: ### this should never happen but happens in Windows
   pass
   if self._forget:
   response.session_file.close()
   del response.session_file


Re: [web2py] Re: Long-running controllers

2011-01-19 Thread ron_m
There is another subtle problem. If the file close is not done after the 
unlock which is how it works now then the file is still open. It is not 
possible to get the exclusive lock in session.connect() until the file is 
closed so the second request remains blocked.


Re: [web2py] Re: Long-running controllers

2011-01-19 Thread Jonathan Lundell
On Jan 19, 2011, at 11:06 AM, ron_m wrote:
> There is another subtle problem. If the file close is not done after the 
> unlock which is how it works now then the file is still open. It is not 
> possible to get the exclusive lock in session.connect() until the file is 
> closed so the second request remains blocked.

Although session.forget(response) seems to work as expected.

[web2py] Re: Long-running controllers

2011-01-19 Thread ae
On Jan 19, 10:14 am, ae  wrote:
> Well, maybe not.  I just downloaded 1.91.6 and I couldn't replicate
> the behavior.  We use 1.67.1 in production and what I tested on might
> have been even older than that.

So I'm back to not sure again.  When I tested earlier I used the --
maxthreads option, but looking at it more carefully, it appears that --
maxthreads has no effect unless you also pass --minthreads (I'm on
Linux).

Even so, I was able to have three browsers open, each blocking one of
two threads.  The third would request a fast-running function and it
was able to use whichever thread was freed first.  For better or
worse, it appears that one user can now use multiple threads at the
same time (but only if calling different functions).

I ran into an odd scenario:

web2py is started with --minthreads=2 --maxthreads=2

lets say applications/test/controllers/default.py looks like:

def sleeper():
import time
time.sleep(60)
return str(time.time())

def gethi():
return "hi"


You have two PCs:  pc1, pc2

In a browser window with 2 tabs, pc1 hits sleeper() in each tab.

pc2 tries to hit gethi() but is blocked.

After about 60 seconds in tab1 on pc1, the function returns.
Then, pretty fast, pc2's call to gethi() returns.
Then after about 60 more seconds, pc1's second tab's call to sleeper()
returns.

It sounds like only 1 thread was used.  This seems like a bug--as if
there's a counter of the number of threads and the counter was
decremented and then the server decided that a single browser couldn't
run the same function in different threads at the same time.  The
third came along and even though the second thread was free, it wasn't
used.

>From two different browsers on the same host, I was able to use two
threads and block a third browser on a different host.  The third
browser seemed to get whichever thread finished first.  That's good.

It doesn't seem like I'm going to get predictable behavior, so I guess
I should just not execute any long-running functions.


Re: [web2py] Re: Long-running controllers

2011-01-19 Thread ron_m
Maybe it is a Windows only issue, I was reviewing the flock(2) man page and 
it isn't a problem in UNIX systems. I haven't looked at the Windows docs but 
remember file access is more restrictive on that system. For now it is only 
a suspicion, I don't use Windows so would have to do a lot to test it.


[web2py] Re: Apache, Wsgi problem

2011-01-19 Thread Massimo Di Pierro
Thanks this is very helpful and I will try reproduce it.
Are you running the trunk version or which other version?

Massimo

On Jan 19, 12:45 pm, VP  wrote:
> UPDATE:  I am able to reproduce this "Premature end of script headers:
> wsgihandler.py" error with a slightly modified app based on the image
> blog in the web2py book.   I modified it so that images are shown in
> the index page, instead of having just the titles listed.
>
> Testing using: ab -kc 100 -t 20https://domain.com/imageblog/default/index/
>
> If I am simply doing this, there's no error.  BUT when I was running
> this test, while simultaneously browsing the website, clicking on
> images, etc., then the error appeared, consistently.
>
> Monitoring available RAM while running this test showed system RAM
> peeked at about 500MB, still a few hundreds MB available. This is on
> the same server as the other app.  VPS. 768MB RAM.  1GB RAM
> Burstable.   About 129 apache2 processes running and 11,000 files
> openning.
>
> sudo ps aux | grep apache2 | wc
>     129    1675   11847
>
> sudo lsof | wc
>   10982  106870 1313126
>
> =
> Here's a typical Apache Bench result:
>
> Server Software:        Apache/2.2.9
> Server Port:            443
> SSL/TLS Protocol:       TLSv1/SSLv3,DHE-RSA-AES256-SHA,1024,256
>
> Document Path:          /imageblog/default/index/
> Document Length:        13130 bytes
>
> Concurrency Level:      100
> Time taken for tests:   20.004 seconds
> Complete requests:      588
> Failed requests:        15
>    (Connect: 0, Receive: 0, Length: 15, Exceptions: 0)
> Write errors:           0
> Non-2xx responses:      15
> Keep-Alive requests:    573
> Total transferred:      7875930 bytes
> HTML transferred:       7564607 bytes
> Requests per second:    29.39 [#/sec] (mean)
> Time per request:       3401.991 [ms] (mean)
> Time per request:       34.020 [ms] (mean, across all concurrent
> requests)
> Transfer rate:          384.50 [Kbytes/sec] received
>
> Connection Times (ms)
>               min  mean[+/-sd] median   max
> Connect:        0  912 2146.5      0    7265
> Processing:    86 2234 1303.3   2781    4427
> Waiting:       85 2136 1281.0   2759    4316
> Total:         86 3146 2410.6   3017   10478
>
> Percentage of the requests served within a certain time (ms)
>   50%   3017
>   66%   3222
>   75%   3939
>   80%   4029
>   90%   7089
>   95%   9409
>   98%  10098
>   99%  10223
>  100%  10478 (longest request)
>
> =
>
> Relevant excerpt of db.py:
>
>     db = DAL('postgres://username:password@localhost:5432/imageblog',
> pool_size=20)
>
> =
> Model:
>
> db.define_table('image',
>    Field('title'),
>    Field('file', 'upload'))
>
> db.define_table('comment',
>    Field('image_id', db.image),
>    Field('author'),
>    Field('email'),
>    Field('body', 'text'))
>
> db.image.title.requires = IS_NOT_IN_DB(db, db.image.title)
> db.comment.image_id.requires = IS_IN_DB(db, db.image.id, '%(title)s')
> db.comment.author.requires = IS_NOT_EMPTY()
> db.comment.email.requires = IS_EMAIL()
> db.comment.body.requires = IS_NOT_EMPTY()
>
> =
> Controller:
>
> def index():
>     images = db().select(db.image.ALL, orderby=db.image.title)
>     return dict(images=images)
>
> @auth.requires_login()
> def add():
>     form = crud.create(db.image, next = URL('index'))
>     return dict(form=form)
>
> def show():
>     image = db(db.image.id==request.args(0)).select().first()
>     form = SQLFORM(db.comment)
>     form.vars.image_id = image.id
>     if form.accepts(request.vars, session):
>         response.flash = 'your comment is posted'
>     comments = db(db.comment.image_id==image.id).select()
>     return dict(image=image, comments=comments, form=form)
>
> def user():
>     """
>     exposes:
>    http:///[app]/default/user/login
>    http:///[app]/default/user/logout
>    http:///[app]/default/user/register
>    http:///[app]/default/user/profile
>    http:///[app]/default/user/retrieve_password
>    http:///[app]/default/user/change_password
>     use @auth.requires_login()
>         @auth.requires_membership('group name')
>         @auth.requires_permission('read','table name',record_id)
>     to decorate functions that need access control
>     """
>     return dict(form=auth())
>
> def download():
>     """
>     allows downloading of uploaded files
>    http:///[app]/default/download/[filename]
>     """
>     return response.download(request,db)
>
> def call():
>     """
>     exposes services. for example:
>    http:///[app]/default/call/jsonrpc
>     decorate with @services.jsonrpc the functions to expose
>     supports xml, json, xmlrpc, jsonrpc, amfrpc, rss, csv
>     """
>     session.forget()
>     return service()
>
> =
> View (index.html)
>
> {{extend 'layo

[web2py] Re: Long-running controllers

2011-01-19 Thread Massimo Di Pierro
Good catch. Thanks Jonathan.

On Jan 19, 12:45 pm, Jonathan Lundell  wrote:
> On Jan 19, 2011, at 10:26 AM, ron_m wrote:
>
> > If the response is left off the session.forget() parameter list it defaults 
> > to None. The end result then is the session._forget state variable is set 
> > True but the session file is not unlocked in the _unlock function. This 
> > would enhance performance by bypassing the writing of the session file at 
> > the end of the request-response cycle when the session state is unchanged 
> > but won't release the lock to let other requests proceed on that session. I 
> > could see this as a possible use of session.forget(..) so it looks like a 
> > documentation issue.
>
> There's another odd behavior. If you call session.forget(response), then 
> _unlock will eventually be called twice (once for forget, once in the 
> early-out path of _try_store_on_disk).
>
>     def _unlock(self, response):
>         if response and response.session_file:
>             try:
>                 portalocker.unlock(response.session_file)
>             except: ### this should never happen but happens in Windows
>                 pass
>
> Perhaps that's the reason for the "should never happen" exception?
>
> Possible fix:
>
>     def _unlock(self, response):
>         if response and response.session_file:
>             try:
>                 portalocker.unlock(response.session_file)
>             except: ### this should never happen but happens in Windows
>                 pass
>             response.session_file.close()
>             del response.session_file
>
> The logic is subtle, because Session defers the creation of the original 
> session file until _try_store_on_disk, so if you forget() a session before 
> the file is created, it never gets created. I think this logic works, though, 
> assuming that a double unlock happens only because of forget.


[web2py] Re: Apache, Wsgi problem

2011-01-19 Thread Michael Toomim
Yes, this echos my experiences exactly!  Using apache ab benchmark
alone would NOT trigger the error.  I had plenty of RAM available.
Seems to be a concurrency bug.

On Jan 19, 10:53 am, VP  wrote:
> What is curious is that RAM is still available, with this error.
> Monitoring CPU (using top) shows CPU % is about 70% for apache2 (70%
> is probably capped by my VPS host, given to each VPS slice).
>
> And this occurs for a very simple app.  I hope Massimo or someone else
> can reproduce this error with this app.   Note that while testing with
> ab, you might have to browse the site, clicking on images, etc.
> Otherwise, ab just it the same domain name repeatedly.


Re: [web2py] Re: Long-running controllers

2011-01-19 Thread Jonathan Lundell
On Jan 19, 2011, at 11:23 AM, ron_m wrote:
> Maybe it is a Windows only issue, I was reviewing the flock(2) man page and 
> it isn't a problem in UNIX systems. I haven't looked at the Windows docs but 
> remember file access is more restrictive on that system. For now it is only a 
> suspicion, I don't use Windows so would have to do a lot to test it.

Me neither. But closing is surely the best course of action, regardless.

Re: [web2py] Re: Long-running controllers

2011-01-19 Thread Anthony
On Wednesday, January 19, 2011 2:33:55 PM UTC-5, Jonathan Lundell wrote: 
>
> On Jan 19, 2011, at 11:23 AM, ron_m wrote:
> > Maybe it is a Windows only issue, I was reviewing the flock(2) man page 
> and it isn't a problem in UNIX systems. I haven't looked at the Windows docs 
> but remember file access is more restrictive on that system. For now it is 
> only a suspicion, I don't use Windows so would have to do a lot to test it. 
>
> Me neither. But closing is surely the best course of action, regardless.
>
I'm on Windows, so let me know if you need me to test anything.
 
Also, I'm happy to make the changes to session.forget(response) in the book 
if we agree that's always the appropriate way to call it. What about in the 
'call' function in the scaffolding app?
 
Also, I notice the command line options section of the book (
http://web2py.com/book/default/chapter/04?search=shell#Command-Line-Options) 
still refers to the --numthreads option -- should that be replaced with the 
newer --minthreads and --maxthreads options?
 
Thanks.
 
Anthony


[web2py] Re: Long-running controllers

2011-01-19 Thread ae
--maxthreads does nothing if you don't specify --minthreads, so that
should be fixed one way or another.  I don't know if that problem is
in web2py or Rocket.


[web2py] Re: Long-running controllers

2011-01-19 Thread ae
Now that I think about it, it seems likely that somewhere something's
doing:

if maxthreads < minthreads:
maxthreads = minthreads


On Jan 19, 2:48 pm, ae  wrote:
> --maxthreads does nothing if you don't specify --minthreads, so that
> should be fixed one way or another.  I don't know if that problem is
> in web2py or Rocket.


[web2py] Re: Apache, Wsgi problem

2011-01-19 Thread VP
I am running the official version 1.91.6.



On Jan 19, 1:24 pm, Massimo Di Pierro 
wrote:
> Thanks this is very helpful and I will try reproduce it.
> Are you running the trunk version or which other version?
>
> Massimo
>
> On Jan 19, 12:45 pm, VP  wrote:
>
> > UPDATE:  I am able to reproduce this "Premature end of script headers:
> > wsgihandler.py" error with a slightly modified app based on the image
> > blog in the web2py book.   I modified it so that images are shown in
> > the index page, instead of having just the titles listed.
>
> > Testing using: ab -kc 100 -t 20https://domain.com/imageblog/default/index/
>
> > If I am simply doing this, there's no error.  BUT when I was running
> > this test, while simultaneously browsing the website, clicking on
> > images, etc., then the error appeared, consistently.
>
> > Monitoring available RAM while running this test showed system RAM
> > peeked at about 500MB, still a few hundreds MB available. This is on
> > the same server as the other app.  VPS. 768MB RAM.  1GB RAM
> > Burstable.   About 129 apache2 processes running and 11,000 files
> > openning.
>
> > sudo ps aux | grep apache2 | wc
> >     129    1675   11847
>
> > sudo lsof | wc
> >   10982  106870 1313126
>
> > =
> > Here's a typical Apache Bench result:
>
> > Server Software:        Apache/2.2.9
> > Server Port:            443
> > SSL/TLS Protocol:       TLSv1/SSLv3,DHE-RSA-AES256-SHA,1024,256
>
> > Document Path:          /imageblog/default/index/
> > Document Length:        13130 bytes
>
> > Concurrency Level:      100
> > Time taken for tests:   20.004 seconds
> > Complete requests:      588
> > Failed requests:        15
> >    (Connect: 0, Receive: 0, Length: 15, Exceptions: 0)
> > Write errors:           0
> > Non-2xx responses:      15
> > Keep-Alive requests:    573
> > Total transferred:      7875930 bytes
> > HTML transferred:       7564607 bytes
> > Requests per second:    29.39 [#/sec] (mean)
> > Time per request:       3401.991 [ms] (mean)
> > Time per request:       34.020 [ms] (mean, across all concurrent
> > requests)
> > Transfer rate:          384.50 [Kbytes/sec] received
>
> > Connection Times (ms)
> >               min  mean[+/-sd] median   max
> > Connect:        0  912 2146.5      0    7265
> > Processing:    86 2234 1303.3   2781    4427
> > Waiting:       85 2136 1281.0   2759    4316
> > Total:         86 3146 2410.6   3017   10478
>
> > Percentage of the requests served within a certain time (ms)
> >   50%   3017
> >   66%   3222
> >   75%   3939
> >   80%   4029
> >   90%   7089
> >   95%   9409
> >   98%  10098
> >   99%  10223
> >  100%  10478 (longest request)
>
> > =
>
> > Relevant excerpt of db.py:
>
> >     db = DAL('postgres://username:password@localhost:5432/imageblog',
> > pool_size=20)
>
> > =
> > Model:
>
> > db.define_table('image',
> >    Field('title'),
> >    Field('file', 'upload'))
>
> > db.define_table('comment',
> >    Field('image_id', db.image),
> >    Field('author'),
> >    Field('email'),
> >    Field('body', 'text'))
>
> > db.image.title.requires = IS_NOT_IN_DB(db, db.image.title)
> > db.comment.image_id.requires = IS_IN_DB(db, db.image.id, '%(title)s')
> > db.comment.author.requires = IS_NOT_EMPTY()
> > db.comment.email.requires = IS_EMAIL()
> > db.comment.body.requires = IS_NOT_EMPTY()
>
> > =
> > Controller:
>
> > def index():
> >     images = db().select(db.image.ALL, orderby=db.image.title)
> >     return dict(images=images)
>
> > @auth.requires_login()
> > def add():
> >     form = crud.create(db.image, next = URL('index'))
> >     return dict(form=form)
>
> > def show():
> >     image = db(db.image.id==request.args(0)).select().first()
> >     form = SQLFORM(db.comment)
> >     form.vars.image_id = image.id
> >     if form.accepts(request.vars, session):
> >         response.flash = 'your comment is posted'
> >     comments = db(db.comment.image_id==image.id).select()
> >     return dict(image=image, comments=comments, form=form)
>
> > def user():
> >     """
> >     exposes:
> >    http:///[app]/default/user/login
> >    http:///[app]/default/user/logout
> >    http:///[app]/default/user/register
> >    http:///[app]/default/user/profile
> >    http:///[app]/default/user/retrieve_password
> >    http:///[app]/default/user/change_password
> >     use @auth.requires_login()
> >         @auth.requires_membership('group name')
> >         @auth.requires_permission('read','table name',record_id)
> >     to decorate functions that need access control
> >     """
> >     return dict(form=auth())
>
> > def download():
> >     """
> >     allows downloading of uploaded files
> >    http:///[app]/default/download/[filename]
> >     """
> >     return response.download(request,db)
>
> > def call():
> >     """
> >     exposes serv

Re: [web2py] Re: Long-running controllers

2011-01-19 Thread Jonathan Lundell
On Jan 19, 2011, at 11:43 AM, Anthony wrote:
> On Wednesday, January 19, 2011 2:33:55 PM UTC-5, Jonathan Lundell wrote:
> On Jan 19, 2011, at 11:23 AM, ron_m wrote:
> > Maybe it is a Windows only issue, I was reviewing the flock(2) man page and 
> > it isn't a problem in UNIX systems. I haven't looked at the Windows docs 
> > but remember file access is more restrictive on that system. For now it is 
> > only a suspicion, I don't use Windows so would have to do a lot to test it.
> Me neither. But closing is surely the best course of action, regardless.
> 
> I'm on Windows, so let me know if you need me to test anything.
>  
> Also, I'm happy to make the changes to session.forget(response) in the book 
> if we agree that's always the appropriate way to call it. What about in the 
> 'call' function in the scaffolding app?

I think we'll probably want to leave the functionality of session.forget() 
alone (no unlock, but suppress the write), and document the unlocking function 
of session.forget(response). 

I don't know which forget calls should have response added. In particular, 
maybe the Service calls need serialization; I don't know.

>  
> Also, I notice the command line options section of the book 
> (http://web2py.com/book/default/chapter/04?search=shell#Command-Line-Options) 
> still refers to the --numthreads option -- should that be replaced with the 
> newer --minthreads and --maxthreads options?
> 

Yes, it should. --numthreads is still supported for legacy purposes, but it's 
not very useful with Rocket, and documenting the legacy behavior would be more 
confusing than helpful.



[web2py] Re: Long-running controllers

2011-01-19 Thread Anthony
On Wednesday, January 19, 2011 2:51:25 PM UTC-5, ae wrote: 
>
> Now that I think about it, it seems likely that somewhere something's 
> doing: 
>
> if maxthreads < minthreads: 
> maxthreads = minthreads 

 
I'm not sure about that, but I found this great Monty Python reference while 
looking into it:
 
def bring_out_your_dead(self):
# Remove dead threads from the pool


[web2py] Re: Apache, Wsgi problem

2011-01-19 Thread VP
It seems the links to the images don't work anymore.  You can just
picked any 10 images, but again the ones I used are:

http://i.imgur.com/u6gwu.jpg
http://i.imgur.com/kJNwj.jpg
http://i.imgur.com/DsjQx.jpg
http://i.imgur.com/HIIN9.jpg
http://i.imgur.com/9AqEI.jpg
http://i.imgur.com/I5Pvh.jpg
http://i.imgur.com/1gxag.jpg
http://i.imgur.com/EcoJr.jpg
http://i.imgur.com/u2ucY.jpg
http://i.imgur.com/3583C.jpg


Re: [web2py] Re: Long-running controllers

2011-01-19 Thread Anthony
On Wednesday, January 19, 2011 2:58:33 PM UTC-5, Jonathan Lundell wrote: 
>
>  Also, I notice the command line options section of the book (
> http://web2py.com/book/default/chapter/04?search=shell#Command-Line-Options) 
> still refers to the --numthreads option -- should that be replaced with the 
> newer --minthreads and --maxthreads options?
>
> Yes, it should. --numthreads is still supported for legacy purposes, but 
> it's not very useful with Rocket, and documenting the legacy behavior would 
> be more confusing than helpful.
>
 
OK, for now I just fixed the command line options section.


Re: [web2py] Re: Long-running controllers

2011-01-19 Thread Jonathan Lundell
On Jan 19, 2011, at 11:48 AM, ae wrote:
> 
> --maxthreads does nothing if you don't specify --minthreads, so that
> should be fixed one way or another.  I don't know if that problem is
> in web2py or Rocket.

I can't find a problem. How did it present itself?

One thing to keep in mind is that the default for maxthreads in web2py is None, 
which translates to 0 in Rocket, which means "unlimited". 

Re: [web2py] Re: Shell & controllers & views

2011-01-19 Thread Anthony
Would exec_environment() be useful here: 
http://web2py.com/book/default/chapter/04#Execution-Environment

On Wednesday, January 19, 2011 11:47:26 AM UTC-5, rochacbruno wrote:

> 2011/1/19 Massimo Di Pierro 
>  
>> No. You can only access the models.
>
>
> I wonder if it is possible to start web2py in Shell mode, execute a 
> controller under the web2py environment.
> inspect the controllers 'return' or use template.py to evaluate a view file 
> passing the controller return as argument.
>
> is there something like that?
>
> 
> $python web2py.py -S myapp -M -P
> >>> db.tables
> ['mytable'] 
> >>> my_return = execfile(/controllers/controller.py)
> >>> print my_return['someobject']
> >>> from gluon.template import *
> >>> print template.parse('/views/controller.html',response._vars=my_return)
> '.
>
> 
>
> I guess I saw something like this in web2py_test_runner.
>
> If something like that could be possible, this will be easy to UnitTest 
> web2py controllers and views.
>


Re: [web2py] Re: Shell & controllers & views

2011-01-19 Thread Bruno Rocha
So, the answer is YES, you can interact with controllers within the shell, I
think web2py could have some helper to wrap that.

< file '/controllers/default.py'>
def sum():
n = request.vars.num
return 1+n



>>> from gluon.shell import exec_environment
>>> request.vars

>>> request.vars.num = 4
>>> request.vars

>>> other =
exec_environment('applications/welcome/controllers/default.py',request=request)
>>> other.soma()
5


The same can do with views parsing it using template.py

--
Bruno Rocha
http://about.me/rochacbruno/bio


Re: [web2py] Re: Long-running controllers

2011-01-19 Thread ron_m
I was talking about the _unlock call at the top of _try_store_on_disk

def _try_store_on_disk(self, request, response):
if not hasattr(os,'mkdir'): return
if response._dbtable_and_field \
or not response.session_id \
or self._forget:
self._unlock(response)
return

The session.forget(response) would remove the attribute session_file if a 
del session_file occurs in _unlock() but self._forget being true will cause 
the _unlock to run again in the branch above and at the top of _unlock the 
if response and response.session_file would cause AttributeError. This piece 
of code is very intricate. :-)




[web2py] Re: Long-running controllers

2011-01-19 Thread ae
I think the default minimum is 8 and it seems there are 3 other
'overhead' threads. (if I just start web2py without any thread
options, ps shows 11 threads.)

If I do --maxthreads=2, I get 11 threads total.

If I do --minthreads=2 --maxthreads=2, I get 5 total (3 + 2?)

So, since the default is 8 and I'm setting max to 2, it seems likely
that somethings doing: max = min if max < min else max

On Jan 19, 3:16 pm, Jonathan Lundell  wrote:
> On Jan 19, 2011, at 11:48 AM, ae wrote:
>
>
>
> > --maxthreads does nothing if you don't specify --minthreads, so that
> > should be fixed one way or another.  I don't know if that problem is
> > in web2py or Rocket.
>
> I can't find a problem. How did it present itself?
>
> One thing to keep in mind is that the default for maxthreads in web2py is 
> None, which translates to 0 in Rocket, which means "unlimited".


Re: [web2py] Re: Shell & controllers & views

2011-01-19 Thread Bruno Rocha
Simply:
>>>
exec_environment('applications/welcome/controllers/default.py',request=request).sum()
5


Bruno Rocha
http://about.me/rochacbruno/bio


Re: [web2py] Re: Long-running controllers

2011-01-19 Thread Jonathan Lundell
On Jan 19, 2011, at 12:32 PM, ron_m wrote:
> I was talking about the _unlock call at the top of _try_store_on_disk
> 
> def _try_store_on_disk(self, request, response):
> if not hasattr(os,'mkdir'): return
> if response._dbtable_and_field \
> or not response.session_id \
> or self._forget:
> self._unlock(response)
> return
> 
> The session.forget(response) would remove the attribute session_file if a del 
> session_file occurs in _unlock() but self._forget being true will cause the 
> _unlock to run again in the branch above and at the top of _unlock the if 
> response and response.session_file would cause AttributeError. This piece of 
> code is very intricate. :-)

response is also Storage, so response.session_file is None if there's no 
session_file attribute.

That's already the normal case (I think) if you call session.forget(response) 
before the session file exists--session_file never gets defined.

Re: [web2py] Re: Long-running controllers

2011-01-19 Thread Jonathan Lundell
On Jan 19, 2011, at 12:32 PM, ae wrote:
> 
> I think the default minimum is 8 and it seems there are 3 other
> 'overhead' threads. (if I just start web2py without any thread
> options, ps shows 11 threads.)

The default minimum is 10 (set in Rocket). I think you're seeing the main 
thread plus the 10 worker threads.

> 
> If I do --maxthreads=2, I get 11 threads total.

That sounds normal, because minthreads (defaulting to 10) is still in effect. I 
could see it being otherwise, but it doesn't bother me much. One problem is 
that web2py doesn't officially know what Rocket's defaults are.

> 
> If I do --minthreads=2 --maxthreads=2, I get 5 total (3 + 2?)

I'm not sure where the 5 would be coming from; I'd expect 3 (main plus two 
workers).

> 
> So, since the default is 8 and I'm setting max to 2, it seems likely
> that somethings doing: max = min if max < min else max




Re: [web2py] Re: Long-running controllers

2011-01-19 Thread ron_m
Okay, I get it, Storage id a dict but adds a __getattr__ which returns None 
on missing key. Nothing like learning in public -- blush.


[web2py] Re: Long-running controllers

2011-01-19 Thread ae
I can say that using two different browsers (FF & Chrome) from the
same host does not exhibit the same behavior as two tabs/windows from
the same browser (same profile...).

On Jan 19, 1:46 pm, ron_m  wrote:
> I remember session.forget() documented as a performance enhancement - no
> plans to alter session on this call, do this to save the write. I think this
> would be the most common use. Adding the response parameter to unlock the
> session file is only required if there is a need for concurrency in the same
> session. Normally this would apply to a user using more than one
> tab/window/browser from the same machine.
>
> I have not explored what happens when you have multiple users behind a NAT
> box because to the server they would all appear to be using the same IP
> address. I need to study up on what causes the server to use a new session.


Re: [web2py] Re: Long-running controllers

2011-01-19 Thread Jonathan Lundell
On Jan 19, 2011, at 12:49 PM, ae wrote:
> 
> I can say that using two different browsers (FF & Chrome) from the
> same host does not exhibit the same behavior as two tabs/windows from
> the same browser (same profile...).

Yes, that's expected. Browsers don't share their cookie jars, so there's no way 
for them to share a session.

> 
> On Jan 19, 1:46 pm, ron_m  wrote:
>> I remember session.forget() documented as a performance enhancement - no
>> plans to alter session on this call, do this to save the write. I think this
>> would be the most common use. Adding the response parameter to unlock the
>> session file is only required if there is a need for concurrency in the same
>> session. Normally this would apply to a user using more than one
>> tab/window/browser from the same machine.
>> 
>> I have not explored what happens when you have multiple users behind a NAT
>> box because to the server they would all appear to be using the same IP
>> address. I need to study up on what causes the server to use a new session.




[web2py] Re: Use the source, Luca

2011-01-19 Thread mikech
This would be a great contribution.  

[web2py] Re: web2py and external editors

2011-01-19 Thread Niphlod
never tried but 2 possibilities arise:
- put all imports in the head of the code  I personally use tips
from http://pierreth.blogspot.com/2010/10/web2py-eclipse-pydev-recipe.html
(search the section starting with "Avoiding warning and errors with
Pydev") with a few variations


- explore the capabilities of pylintrc, init-hook parameter in it and
load the file with --rcfile=



On Jan 18, 9:11 pm, Mike Rans  wrote:
> Hi,
>
> I am a web2py newbie.
>
> I am using web2py with an external text editor. I made Pylint and
> Winpdb plugins for this editor (Editra - which is written in Python)
> and can successfully debug web2py from it.
>
> The problem I have is with Pylint - web2py does some behind the scenes
> importing. I don't want to turn warnings off as that defeats the
> object of Pylint. I can modify the Pylint plugin to do things before
> launching Pylint (and already do so with altering the PYTHONPATH), so
> do you know of a way to tell Pylint about the imports web2py has
> done?
>
> Cheers,
> Mike


[web2py] Re: Long-running controllers

2011-01-19 Thread ae
I understand getting a different session is expected.  I'm talking
about different behavior in how requests are dispatched to threads.
The above scenarios for example which leads me to believe you can't
reliably use long running functions.


Re: [web2py] Re: Long-running controllers

2011-01-19 Thread Jonathan Lundell
On Jan 19, 2011, at 1:45 PM, ae wrote:
> 
> I understand getting a different session is expected.  I'm talking
> about different behavior in how requests are dispatched to threads.
> The above scenarios for example which leads me to believe you can't
> reliably use long running functions.

Again, it's not the threads (as long as you're not starving for them), but 
rather the serialization of requests within sessions that's the concern. If you 
can arrange to call session.forget(response), you should be OK (though as Ron 
suggests, the fact that the session file isn't closed might be an issue under 
Windows, and we'll get that fixed).

However, you still might want to avoid long-running functions as request 
handlers; I'm not trying to persuade you otherwise.

[web2py] Re: Use the source, Luca

2011-01-19 Thread Anthony
On Wednesday, January 19, 2011 1:14:28 AM UTC-5, cjrh wrote: 
>
> There was a malfunction on my link to the module-level documentation 
> that I was referring to (curse you Frames): first go here: 
>
> http://www.web2py.com/examples/static/epydoc/index.html 
>
> And then click on web2py.gluon.dal on the left. You will see module- 
> level documentation on the right, which is already prose-like and 
> descriptive.  This is what I was referring to as a suggested location 
> for the "tour guide to the source code". 

 
Yes, I agree, we should make use of the docstrings as much as possible. 
Though the plain text formatting isn't ideal -- for some docstrings, it 
would be nicer to use the epytext or reST markup that works with Epydoc (or 
maybe modify it to work with markmin, or migrate to an Epydoc alternative, 
as Epydoc is no longer under active development). There are also some topics 
that cut across multiple modules and therefore wouldn't easily fit into the 
Epydoc structure -- though, again, it would be nice if we could simply 
modify the structure a bit to get that material into the same interface 
rather than putting it elsewhere.
 
Best,
Anthony


[web2py] Cached Results Using a Module.

2011-01-19 Thread David J.

Perhaps I missed an important point;

I have an "api.py" which I loaded through the modules directory;

This "api.py" makes calls for data to external web services;

In my controller; I have

api = local_import('api')


def remote():
 api_result = api.xml_request({'id':'123456'})

 return dict(results=api_result)


What seems to happen is the first call to controller makes a call to the 
"api.py" script and I get the results; but lets say I change the 
parameters and reload the page; I see the same results returned. Only if 
I restart the wb2py server do I see the change on the first request and 
then same thing;


so I wonder if maybe this request is stored in cache and it re-uses this 
result on subsequent requests; or perhaps something else is causing this 
problem.


Thanks.





[web2py] Re: Cached Results Using a Module.

2011-01-19 Thread ron_m
If you are editing the file in the modules directory then that is the 
problem. A module gets pulled in and kept by the server until restart unless 
you add a parameter to the local_import()

api = local_import('api', True) where the True says perform a module reload 
on each request.


Re: [web2py] Re: Cached Results Using a Module.

2011-01-19 Thread David J.

Great Thanks I will try;

At what cost am I doing this; Does it add tremendous overhead?

Thanks



On 1/19/11 5:24 PM, ron_m wrote:
If you are editing the file in the modules directory then that is the 
problem. A module gets pulled in and kept by the server until restart 
unless you add a parameter to the local_import()


api = local_import('api', True) where the True says perform a module 
reload on each request.




[web2py] Re: Cached Results Using a Module.

2011-01-19 Thread Massimo Di Pierro
Yes. In production set the second argument to False

On Jan 19, 4:27 pm, "David J."  wrote:
> Great Thanks I will try;
>
> At what cost am I doing this; Does it add tremendous overhead?
>
> Thanks
>
> On 1/19/11 5:24 PM, ron_m wrote:
>
>
>
>
>
>
>
> > If you are editing the file in the modules directory then that is the
> > problem. A module gets pulled in and kept by the server until restart
> > unless you add a parameter to the local_import()
>
> > api = local_import('api', True) where the True says perform a module
> > reload on each request.


Re: [web2py] Re: Cached Results Using a Module.

2011-01-19 Thread David J.

As you said; It worked;

Thanks for the pointer; I appreciate it;

And will set to false in production.

Thanks again.



On 1/19/11 5:27 PM, Massimo Di Pierro wrote:

Yes. In production set the second argument to False

On Jan 19, 4:27 pm, "David J."  wrote:

Great Thanks I will try;

At what cost am I doing this; Does it add tremendous overhead?

Thanks

On 1/19/11 5:24 PM, ron_m wrote:








If you are editing the file in the modules directory then that is the
problem. A module gets pulled in and kept by the server until restart
unless you add a parameter to the local_import()
api = local_import('api', True) where the True says perform a module
reload on each request.




Re: [web2py] Re: Cached Results Using a Module.

2011-01-19 Thread Jonathan Lundell
On Jan 19, 2011, at 2:32 PM, David J. wrote:
> 
> As you said; It worked;
> 
> Thanks for the pointer; I appreciate it;
> 
> And will set to false in production.

I define a PRODUCTION flag in my model, and use it for this purpose as well as 
setting different log levels and cache durations.

> 
> Thanks again.
> 
> 
> 
> On 1/19/11 5:27 PM, Massimo Di Pierro wrote:
>> Yes. In production set the second argument to False
>> 
>> On Jan 19, 4:27 pm, "David J."  wrote:
>>> Great Thanks I will try;
>>> 
>>> At what cost am I doing this; Does it add tremendous overhead?
>>> 
>>> Thanks
>>> 
>>> On 1/19/11 5:24 PM, ron_m wrote:
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
 If you are editing the file in the modules directory then that is the
 problem. A module gets pulled in and kept by the server until restart
 unless you add a parameter to the local_import()
 api = local_import('api', True) where the True says perform a module
 reload on each request.
> 




Re: [web2py] Re: Long-running controllers

2011-01-19 Thread Jonathan Lundell
On Jan 19, 2011, at 7:15 AM, Anthony wrote:
> On Wednesday, January 19, 2011 1:35:09 AM UTC-5, Jonathan Lundell wrote:
> Actually, there's a bug in the documentation (or else in Session). You have 
> to say:
> 
> session.forget(response)
> 
> or else the session doesn't get unlocked
> 
> There are at least four occurrences of session.forget() in the book, and one 
> in the 'call' action in the default.py controller of the 'welcome' app. 
> Should all of those be replaced with session.forget(response)? Is there any 
> reason to use session.forget() with the default response=None (which sets 
> session._forget=True but does not unlock the session file)? If not, maybe the 
> default behavior of session.forget() itself should be changed.

This belated reply might be redundant, but never mind...

I don't think we want to change the default behavior of session.forget(), 
because it might break existing applications. At the very least, they haven't 
been tested in the unlock-session mode if they're calling session.forget() 
without an argument.

The book's mention of session.forget isn't actually wrong:

The session object has two important methods. One is forget:

1.
session.forget()
It tells web2py not to save the session. This should be used in those 
controllers whose actions are called often and do not need to track user 
activity.



That's actually true. What we need is another paragraph to document 
session.forget(response), explaining that it disables session serialization. 
For most apps, there's probably not much need to do this. I have an app that 
dynamically generates its main css file, and it would be useful for that not to 
have to wait for the main page to finish loading, but even there the css file 
will ordinarily be cached by the browser, so it doesn't make much difference.



[web2py] JSON Data

2011-01-19 Thread contatogilson...@gmail.com
Hello guys,

I'm wanting an action returns a json like this:

{

"start": "2011-01-27",

"id": 4,

"title": "Fulano Silva"

}



Only to send to the view he is being rendered thus:

"{\n \"start\": \"2011-01-27\", \n
\"id\": 4, \n \"title\": \"Fulano
Silva\"\n}"


The code I made to return the JSON looks like:

import simplejson as json

def index():

# Consultando os servicos do usuario logado

query = db.agenda.id > 0 and db.agenda.funcionario ==
> session.auth.user.id and db.agenda.cliente == db.cliente.id

 agenda = db(query).select(orderby = db.agenda.data)

teste2 = list(agenda)

for ag in agenda:

teste =
json.dumps({"id":ag.agenda.id,"title":ag.cliente.nome,"start":ag.agenda.data.strftime('%Y-%m-%d')},indent=4)
>

return dict(teste = response.json(teste))



What should I do?
_
*Gilson Filho*
*Web Developer
Blog:* blog.gilsondev.com
*Twitter:* twitter.com/gilsonfilho


[web2py] Re: web2pyslices migration

2011-01-19 Thread Plumo
wow - sounds fantastic!



[web2py] Re: web2py and external editors

2011-01-19 Thread Plumo
I use Komodo Edit, and to deal with the imports I made a plugin that 
executed this implicitly in every Python file:

if 0:
from gluon.globals import *
from gluon.html import *
from gluon.http import *
from gluon.sqlhtml import SQLFORM, SQLTABLE, form_factory
session = Session()
request = Request()
response = Response()



[web2py] Re: web2py website and 404's

2011-01-19 Thread Matt
Could this be configurable? I.e. have a setting in the router to
specify if we want a 400 or 404 when this occurs?

Matt

On Jan 20, 5:43 am, Jonathan Lundell  wrote:
> On Jan 19, 2011, at 3:55 AM, Albert Abril wrote:
>
> > Just a suggestion.
>
> > When I an incorrect url, for example:
> >http://web2py.com/layout (instead ofhttp://web2py.com/layouts)
>
> > ...appears an "invalid controller" error, as it's expected.
>
> > What if it instead is shown a nicer 404?
>
> Right now it's a 400 error: bad request. It probably *should* be a 404, 
> though the "invalid controller" text is useful (I think) in explaining where 
> the URL went wrong. You can manage this yourself, to some extent anyway, 
> through routes.py.


[web2py] Re: geo spatial GIS in web2py

2011-01-19 Thread KK
Anything?  This is very discouraging.

How about this?  Would it be possible to run geodjango and web2py on the 
same server?  I'd like my main site to be served by web2py.  Then provide a 
link on the webpage to http://mysite/geospatial/, at which point geodjango 
takes over and starts serving pages.  Is this possible?  Would it be 
possible for these two applications to use the same database backend?

Thanks.


[web2py] Re: geo spatial GIS in web2py

2011-01-19 Thread Massimo Di Pierro
One year ago a user (do not recall his name) implemented something
like geodjango in web2py dal. This was a master thesis project. He was
not my student but I have the code somewhere.It was never merged to
trunk because the patch was for a very old version of web2py.

There is also this: https://launchpad.net/web2py-geo
which may be related but appears dead.

For me this is not a priority but I will try find the code and post it
in case others want to look at it.

massimo


On Jan 19, 10:40 pm, KK  wrote:
> Anything?  This is very discouraging.
>
> How about this?  Would it be possible to run geodjango and web2py on the
> same server?  I'd like my main site to be served by web2py.  Then provide a
> link on the webpage tohttp://mysite/geospatial/, at which point geodjango
> takes over and starts serving pages.  Is this possible?  Would it be
> possible for these two applications to use the same database backend?
>
> Thanks.


[web2py] error with mod_wsgi on shared host

2011-01-19 Thread Cory Coager
This is a new setup of web2py using mod_wsgi on a shared host.  Any
idea what is wrong?

.htaccess:
SetHandler wsgi-script
Options +ExecCGI
RewriteEngine On
RewriteRule ^((static|auth|admin|mycontroller).*)$ /wsgihandler.py/
myapp/$1 [QSA,PT,L]

Error logs:
[Wed Jan 19 17:52:06 2011] [error] [client 127.0.0.1]   File "/home/
user/gluon/utils.py", line 10, in ?
[Wed Jan 19 17:52:06 2011] [error] [client 127.0.0.1]   File "/home/
user/restricted.py", line 18, in ?
[Wed Jan 19 17:52:06 2011] [error] [client 127.0.0.1]   File "/home/
user/gluon/main.py", line 32, in ?
[Wed Jan 19 17:52:06 2011] [error] [client 127.0.0.1]   File "/home/
user/wsgihandler.py", line 27, in ?
[Wed Jan 19 17:52:06 2011] [error] [client 127.0.0.1] mod_wsgi
(pid=4975): Exception occurred processing WSGI script '/home/user/
wsgihandler.py'.
[Wed Jan 19 17:52:06 2011] [error] [client 127.0.0.1] mod_wsgi
(pid=4975): Target WSGI script '/home/user/wsgihandler.py' cannot be
loaded as Python module.


[web2py] Re: Cached Results Using a Module.

2011-01-19 Thread cjrh
On Jan 20, 12:39 am, Jonathan Lundell  wrote:
> I define a PRODUCTION flag in my model, and use it for this purpose as well 
> as setting different log levels and cache durations.

And for migration support, I'm guessing.  I do the same thing.


  1   2   >