Hi Anthony,

Thanks for the pointer. I took each variable in turn and fed it through
      return dict(foo = variable1)

ran & check for hang
      return dict(foo = variable2)

ran & check for hang...


Narrowed it down to 3 lists of tuples. 

In all cases the view code was:
    {{=BEAUTIFY(foo)}}

for most variables, no problem. For the 3 lists of tuples, hang the server.

Then I eliminated the BEAUTIFY function, and just made a loop in the view:

{{ for items in foo:}}
{{ =items}}
{{pass}}

This worked. No hang. So it has nothing to do with return locals(), but 
seems to be BEAUTIFY specifically with these lists.

Finally, in the controller I made a loop to copy the list item by item into 
a new list, and return that to BEAUTIFY:

    tmp = []
    for items in variable1:
        tmp.append(items)

    return dict(foo=tmp)

On the silly thought that it might clean up whatever data structure was 
there. It didn't. Still had the hang.

At this point I would have to crack open the BEAUTIFY function and trace 
through it, and honestly I don't even know where to begin. I have put 
enough time into this to pretty much rule out the code and the variables I 
have. The debuggers show this as a list of 3 tuples. When I use the item 
loop in view, it shows a simple list of 3 tuples. It just isn't that 
complex of a data structure to be giving me so much headache. In fact, here 
it is:

(1L, 0.23359594244831011) (2L, 1.600167232663812e-05) (3L, 
1.3562750608171854e-10)

This is so frustrating - so I put that exact list into a variable and 
passed it to BEAUTIFY. Of course that worked:

    tmp =[(1L, 0.23359594244831011), (2L, 1.600167232663812e-05), (3L, 
1.3562750608171854e-10)]
    return dict(foo=tmp)

Directly passing the exact list works with BEAUTIFY, it works if I iterate 
through the items in the view. Can't break it.  For some reason the 
function that generates the list creates it in a way that has no visible 
problem, works when I iterate through the list, looks fine in the debugger, 
but does not work with BEAUTIFY.



A hang is pretty serious, but this is getting beyond my ability to debug. I 
really wouldn't know where to start digging into BEAUTIFY, underlying 
memory, or exceptions gone wrong...Also given that I am having a general 
memory leak on El Capitan, and nobody else is complaining about such a 
hang, it smells like a problem on my OS interacting with BEAUTIFY.



On Saturday, July 2, 2016 at 8:06:31 AM UTC-7, Anthony wrote:
>
> Note that locals() is a dictionary including all objects defined in the 
> local scope (i.e., your controller function). Perhaps something else in 
> locals() is causing the problem. Maybe trying returning an explicitly 
> constructed dictionary instead:
>
>     return dict(bob=bob)
>
> Otherwise, without seeing your code or having a way to replicate, it is 
> difficult to help. You might try doing some inspection of what exactly is 
> being fed to BEAUTIFY. In general, a list of tuples should be no problem, 
> and how that list of tuples was generated (e.g., via sorted or otherwise) 
> should not matter.
>
> Anthony
>
> On Saturday, July 2, 2016 at 2:02:45 AM UTC-4, DNeuman wrote:
>>
>> I have attempted creating a test app a few times. I have spent a week on 
>> this so far, with no real progress. Nothing seems to trigger the problem 
>> other than the full app.
>>
>> It seems very strange that passing local variables to BEAUTIFY as a list 
>> of tuples works in a small app. Yet when the same list of tuples is 
>> generated from sorted() it does not work. I even tried putting a sorted() 
>> function on a dict in a test app, and it worked with a small app, but not 
>> the full app. Very flakey.
>>
>> Is BEAUTIFY and return locals() meant to work with a list of tuples? If 
>> not, I'll just rewrite this. I thought it might work, but currently its 
>> behavior is unpredictable. Sorry I don't have more details. If I am trying 
>> to do something web2py wasn't meant to do, that would help me at least. 
>> Please let me know.
>>
>> Thanks,
>>
>> On Saturday, June 18, 2016 at 9:08:50 PM UTC-7, Anthony wrote:
>>>
>>> Probably something else is going on. I suggest you create a minimal app 
>>> that reproduces the problem and post it.
>>>
>>> Anthony
>>>
>>> On Saturday, June 18, 2016 at 8:47:42 AM UTC-4, DNeuman wrote:
>>>>
>>>> Hi - first time posting here! First let me say thanks to Professor Di 
>>>> Pierro and all the people who have done a great job on Web2Py. I am new to 
>>>> web development, and Python, so I really appreciate all the work you did 
>>>> to 
>>>> make this subject approachable. Now for my question:
>>>>
>>>> I am having some difficulty passing a list of tuples from a controller 
>>>> using  'return locals()'  sometimes it hangs the web2py server.
>>>>
>>>> I have spent a week narrowing this down, and here is what I have; some 
>>>> works, some does not...
>>>>
>>>> If I create a simple list named bob = [(2L, 0.2075327747768832), (16L, 
>>>> 0.19108106970048253), (3L, 0.13288897732583363), (15L, 
>>>> 0.11511204575971237), (12L, 0.10369170755981243), (7L, 
>>>> 0.1033849215142939), 
>>>> (8L, 0.0957849868092478), (5L, 0.05052350890092832)]
>>>>
>>>> then return locals()  I can see this in response._vars  in the debugger 
>>>> and {{=BEAUTIFY(response._vars)}} works fine.          (thats good)
>>>>
>>>>
>>>> However, if I create the same exact list as an output of a sorting 
>>>> operation from a dictionary, it hangs the web2py server when I use return 
>>>> locals() and {{=BEAUTIFY(response._vars)}}       (but only sometimes)
>>>>
>>>>
>>>> Here is what the code is used to generate the sorted list:
>>>>
>>>> def make_list():
>>>>     from operator import itemgetter
>>>>     #dbg.set_trace() # stop here!
>>>>
>>>>     test_dict ={}
>>>>
>>>>     test_dict[2L] = 0.773
>>>>     test_dict[5L] = 0.003
>>>>     test_dict[1L] = 0.31
>>>>     test_dict[9L] = 0.0402
>>>>     test_dict[12L] = 0.12
>>>>     test_dict[7L] = 0.214
>>>>
>>>>     test_list = sorted(test_dict.iteritems(), key=itemgetter(1), 
>>>> reverse=True)
>>>>
>>>>     return test_list             #this should be a list of tuples 
>>>> [(x,y),(w,z)...()]
>>>>
>>>>
>>>> But here is the weird part - if I have this test case standalone, it 
>>>> always works. If I use sorted() in a larger program, it exhibits the hang. 
>>>> Very consistent. standalone test = no problem. larger problem = broken.
>>>>
>>>> More about the server hang:
>>>>
>>>> passing bob through locals() causes a hang, whether BEAUTIFY(bob) or 
>>>> BEAUTIFY(response._vars)    as long as bob is generated from the sorted() 
>>>> function. Never hangs when generated from simply creating a list of tuples.
>>>>
>>>>
>>>> passing bob through locals() doesn’t hang unless BEAUTIFY(bob).  So, if 
>>>> I don't use bob in the view, it doesn't hang. There is something about 
>>>> passing this through locals, AND using BEAUTIFY AND creating the list from 
>>>> sorted() AND being in a larger program.
>>>>
>>>>
>>>> making bob from sorted() in a large program = hang:
>>>>
>>>> use return locals() and BEAUTIFY(response._vars)      -- hang
>>>>
>>>> use return locals() and BEAUTIFY(bob)                        -- hang
>>>>
>>>>
>>>> works:
>>>>
>>>> return locals() and BEAUTIFY(qlist)                                     
>>>>            -- no hang; qlist is some other variable
>>>>
>>>> return locals() and use view {{=bob[0]   =bob[1]   =bob[2] }}           
>>>> -- no hang; here I simply don't use BEAUTIFY and it all works
>>>>
>>>> bob created without using sorted()                                     
>>>>              -- no hang; can do whatever I like and it works.
>>>>
>>>>
>>>>
>>>> So I can only guess that I am using sorted() wrong, or using BEAUTIFY 
>>>> wrong, or there is some very mysterious aspect of the list that is not 
>>>> visible in the debugger which is confusing BEAUTIFY.
>>>>
>>>>
>>>> when I examine response._vars in cases where there is a hang it is 
>>>> identical to cases where there is no hang.
>>>>
>>>>
>>>> details:
>>>>
>>>> Mac OS X El Capitan  10.11.5
>>>>
>>>> Web2py 2.14.2-stable+timestamp.2016.03.24.22.47.49
>>>>
>>>> modules installed: numpy
>>>>
>>>> browser: Safari
>>>>
>>>>
>>>> Much appreciate any pointers here! Thanks.
>>>>
>>>>

-- 
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.

Reply via email to