Probably you are running web2py from source with your own Python
installation and have not installed the pywin32
<http://sourceforge.net/projects/pywin32/> extension (which is required for
file locking).
Anthony
On Monday, August 10, 2015 at 8:06:12 PM UTC-4, Val K wrote:
>
> As I see, the problem is that ajax request (may be not ajax only) didn't
> wait for closing session file by another one and read/save data from/to it
> at any time! Lock did not work on my Win7 because , as I think, for Win
> it's one process.
> Request processing may be not pure parallel but fully asynchronous - I
> placed some print statement in ajax controller and got full chaos - among
> print from one request were one from another.
> Here is my littlle test. 3 ajax calls start at once but finish
> asynchronously (time.sleep()). By change time.sleep() it's possible to
> get any order (I did "start first - finish last"). At the end of all
> session contains only vars/changes of ajax which finish last.
>
>
>
> import time
>
> # it's a funny AJAX test
> #just create new app and paste it in the default controller
> # call .../default/many_ajx_form
>
> def ajx_bug():
> if request.args(0)=='0':
> time.sleep(10) # well, now wait until fish fall asleep in the pond
> session.req_0='Only req_0 ... nothing else!!! Where are req_1,
> req_2 and other kids? It seems, that guys ignored my session lock?'
> elif request.args(0)=='1':
> time.sleep(5)
> session.req_1='I killed req_2 and created req_1 which will be
> killed by req_0 !'
> else:
> session.req_2='I created req_2'
> response.flash="click 'Print Session' !"
> if request.args(0)=='0':
> return dict(ret='Better late than never')
> else:
> return dict(ret='completed req_%s'%request.args(0))
>
> def print_session():
> lst=[]
> for k,v in session.items():
> lst.append(DIV(
> DIV(k,_class='col-xs-2', _style="font-weight:bold;
> text-align:right; min-height:50px"),
> DIV(':',_class='col-xs-1'),
> DIV(v,_class='col-xs-9'),
> _class='row'
> )
> )
> return dict(r=DIV(*lst, _class="container", _style="max-width:800px"))
>
>
>
> #------------ CALL THIS --------------------
> def many_ajx_form():
> session.clear() # - for clear test
> session.dummy_data = 'dummy data' # make some action for sure init
> session
> ret={}
> for i in xrange(3):
> ret['ajx_frm_%s'%i]= \
> DIV(
> LOAD('default','ajx_bug.load',
> args=[i],
> ajax=True,
> target='cont_%s'%i
> ),
> _id='cont_%s'%i
> )
>
> btn_prnt=DIV(BUTTON("Print Session", _type="button",_class="btn
> btn-default",
> _onclick=myLOAD_any("default","print_session",
> target="lst")),
> DIV(_id="lst")
> )
>
> ret['z']=btn_prnt
>
> return ret
>
> #return string, no SCRIPT tag!
> def myLOAD_any(contrl, fun, target, args=None, vars=None, ):
>
> if vars:
> vars_str='?'
> for k,v in vars.items():
> vars_str+=('%s=%s&'%(k,v))
> vars_str= vars_str[:-1] # remove last '&'
> else:
> vars_str=''
> if args:
> args_str='/'.join([str(it) for it in args])
> else:
> args_str=''
> data=dict(
> rmt= "/%s/%s/%s.load/%s%s"%(request.application, contrl, fun,
> args_str, vars_str ),
> trg=target
> )
> load_str="""$.web2py.component("%(rmt)s", "%(trg)s", 0, 1,
> $("#%(trg)s"));"""
> return load_str%data
>
>
>
>
>
>
>
> On Monday, August 10, 2015 at 4:05:57 AM UTC+3, Anthony wrote:
>>
>> All responses within the same session are supposed to have the same
>> session_id. The fact that all three Ajax requests can access the session
>> doesn't necessarily mean they are being processed in parallel (the requests
>> might still be completing one after another).
>>
>> It would be helpful if you could attach a minimal app that demonstrates
>> the problem.
>>
>> Anthony
>>
>> On Sunday, August 9, 2015 at 12:30:01 PM UTC-4, Val K wrote:
>>>
>>> I realize your advice - no effect!
>>> I analyzed *session.connect* and found strange place at the biginig
>>> of *connect *definition:
>>> ...
>>> self._unlock(response) # - *unconditional unlock *session file witch
>>> have a name == response.session_id
>>> ...
>>>
>>> Then I changed definition of ajx_bug(): form=SQLFORM.factory(Field('
>>> any', *comment=response.session_id* ), table_name=form_name)
>>> and here is I got:
>>>
>>> Many Ajx Form
>>> ajx_frm_0:
>>> Any
>>> 127.0.0.1-dd2c6b6c-3141-4826-8887-ab1691b67350
>>> ajx_frm_1:
>>> Any
>>> 127.0.0.1-dd2c6b6c-3141-4826-8887-ab1691b67350
>>> ajx_frm_2:
>>> Any
>>> 127.0.0.1-dd2c6b6c-3141-4826-8887-ab1691b67350
>>>
>>>
>>>
>>>
>>>
>>>
>>> All ajax responses have the same response_id! i.e. each ajax-process can
>>> unlock session file locked by another!
>>> In other words, requests parallel processing works properly across
>>> sessions, but not within one session, because all responses within session
>>> have the same response_id
>>> It seems, that file is not locked across parallel process (on my Win7 at
>>> least), may because it is children of one parent or something else?
>>>
>>>
>>>
>>> On Sunday, August 9, 2015 at 3:28:04 PM UTC+3, Anthony wrote:
>>>>
>>>> Does the problem occur only on the first page load of the session? If
>>>> so, does the problem go away if you add the following line at the top of
>>>> the many_ajx_form function:
>>>>
>>>> session.dummy_data = 'dummy data'
>>>>
>>>> If that's the case, then this is the same problem diagnosed in the
>>>> original thread, with something like the above as the solution. The
>>>> problem
>>>> is not that Ajax reads fail to lock the session -- the problem is that at
>>>> the very beginning of the session when the initial set of Ajax requests
>>>> are
>>>> made, there is no session file to lock at all. Adding some dummy data to
>>>> the session in the parent page will force a session file to be created, so
>>>> the session file will then exist and therefore be locked when the Ajax
>>>> requests come in. Note, this won't work with sessions stored in the DB or
>>>> in cookies, as there is no session locking at all with those methods (you
>>>> will need some other means to avoid session race conditions in those
>>>> cases).
>>>>
>>>> Anthony
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.