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