[web2py] How can I run a command once at launch?

2019-09-02 Thread 'Francis Windram' via web2py-users
Hi All,

Seems like a simple question here but I am struggling with finding an 
elegant solution.

I have a scheduler running with one task that runs at around 2200 every 
night, then queues the next run at 2200 the next day. However I am at a 
loss on how to trigger off the first run (aside from a one-off script to 
schedule the first run)

Adding a piece of code in the model which checks whether an eod_run job is 
in the scheduler table and schedules one if not seems like it adds a lot of 
overhead, considering the models are run very regularly.
Assuming that all things work properly, once the scheduler runs one job, it 
should just queue the next one, but I'm not sure if that persists over 
server shutdowns.

Do you have any suggestions? I could drop down and use a cron job on the 
server itself, or using the cron functionality in web2py, but that feels 
like stepping backwards when we have a perfectly functional scheduler 
already enabled.

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 web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/155e91c6-bb4b-4957-a148-383f7b29f603%40googlegroups.com.


[web2py] Help understanding memory use and selects

2019-09-02 Thread Ian W. Scott
I'm trying to lower the memory use of an app and have some general 
questions about how memory is used in DAL selects:


   1. Am I right that the memory used while performing the select isn't 
   released right away, even if the select isn't assigned to a variable? 
   2. I'm aware of iterselect. Am I right that with iterselect the memory 
   used is just enough to store one row of data (instead of the whole selected 
   set)?
   3. Does this mean that, generally, you want to perform as few separate 
   selects as possible, unless you can use iterselect?
   4. Selects seem to occupy a significant amount of memory, even when the 
   result set is only one row. Is the memory use for the select determined by 
   the table size or the result size?

Here's an example of the kind of situation I'm working with. I'm using a 
list comprehension to loop through a list, performing a select in each loop:

p_here = [p for p in cpaths if loc_id in db.steps[int(p['steps'][0])].
locations]


When I run a memory profiler, this line results in over 1MB of memory being 
occupied, and that memory isn't released for at least several minutes. The 
table "steps" has about 3000 rows, so it's not enormous. The result for 
each select is a single row and doesn't include a huge amount of data (a 
few strings, ints, etc.). The "cpaths" list might have 50 or so items. So 
is the memory issue emerging because (a) the memory use for each select is 
determined by the table size, and (b) memory is being occupied (and not 
released) separately for each iteration of the loop? Is there a way to 
rewrite this so that it uses less memory?

-- 
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 web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/d2665636-2694-4262-b3ad-441e1c1f695a%40googlegroups.com.


[web2py] Re: web3py -> py4web

2019-09-02 Thread Klaus Zinser
For both PCs (OSX) I tried to tidy up. With AppCleaner in programs all 
Python (except 3.7) was removed. 
Whats initially coming with Apple OSX will stay and being updated. 
(Currently: Python 2.7.16 (v2.7.16:413a49145e, Mar  2 2019, 15:28:37) [GCC 
4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin

Then from python org the most recent python was installed. Currently 
Version 3.7.4. 


Now in the terminal window 
A: entering: python   -> Python 2.7.16 (v2.7.16:413a49145e, Mar  2 2019, 
15:28:37) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
B: entering python3  -> Python 3.7.4 (v3.7.4:e09359112e, Jul  8 2019, 
14:54:52) [Clang 6.0 (clang-600.0.57)] on darwin

Now, install one of the 4 solutions. Possibly the most easiest is (not 
working before): 

' workflow 1) pip only' (see thread entry 31. Aug here)

python3 -m pip install py4web
py4web-start apps (apps will be created for you)'

It works. On a new macmini (10.14.6) 2018 and on a mid 2010 Macbook (OSX 
10.13.6). (re 'very old pydal version' on the notebook, the web2py.app was 
copied to the notebook prog folder). 
Writing these details should be no advertisement for the company. Most 
realistic the next notebook won't come from them. 

So the infrastructure seems to be fine. On both PCs py4web and web2py is 
working,  



Am Montag, 2. September 2019 04:21:18 UTC+2 schrieb Massimo Di Pierro:
>
> I think this error
>
> AttributeError: type object 'DAL' has no attribute 'Field'
>
> means you have some very very old version of pydal. Is that possible?
>
> On Sunday, 1 September 2019 02:14:38 UTC-7, Klaus Zinser wrote:
>>
>> Thats was working on the Desktop:
>>  
>> workflow 4) from source and install
>>
>> git clone https://github.com/web2py/py4web.git
>>
>> cd py4web
>> make install
>> cd ..
>> mkdir work
>> cd work
>> py4web-start apps
>>
>> For me thats fine and I don't want the risk to destroy. I need to make 
>> sure to keep the code actual. Nothing happenened on this: ./py4web-start 
>> app.py
>>
>> Nevertheless, that was on the desktop. I tried on the notebook: 
>>
>> workflow 1) pip only
>> python3 -m pip install py4web
>> py4web-start apps
>> (apps will be created for you)
>>
>> zvkmcbk:~ klauszinser$ py4web-start app.py
>> Traceback (most recent call last):
>>  File 
>> "/Library/Frameworks/Python.framework/Versions/3.6/bin/py4web-start", line 
>> 11, in 
>> ...  
>> File 
>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/py4web/__init__.py",
>>  
>> line 1, in 
>>from . core import (
>>  File 
>> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/py4web/core.py",
>>  
>> line 209, in 
>>setattr(pydal.DAL.Field, _, threadsafevariable.ThreadSafeVariable())
>> AttributeError: type object 'DAL' has no attribute 'Field'
>> zvkmcbk:~ klauszinser$
>>
>> Right now I am fine as the desktop is working. I will play around with 
>> the notebook and try 1) pip ony setup.
>>
>> For me its now a low priority. 
>>
>> Thank you, Klaus 
>>
>> -
>>
>> Am Sonntag, 1. September 2019 04:50:09 UTC+2 schrieb Massimo Di Pierro:
>>>
>>> This is my bad. We just renamed
>>>
>>> ./py4web-start to ./py4web-start app.py
>>>
>>> the reason is that windows did not understand the former. Does this 
>>> solver the problems?
>>>
>>> On Saturday, 31 August 2019 14:45:14 UTC-7, Klaus Zinser wrote:

 Thanks Val, thanks Massimo,
 as there was the chance to tidy up I took the approach from Massimo. 

 First I tried 
 py4web-start apps -> working
 ./py4web-start apps -> not working
 Then I tried to tidy up. Most realistic I 
 #1 deleted the venv (virtual environment), 
 #2 removed the folder 
 #3 uninstalled
 The I rebooted OSX. 

 When choosing 1) pip only I got these messages: 

 You are using pip version 19.0.3, however version 19.2.3 is available.

 You should consider upgrading via the 'pip install --upgrade pip' 
 command.

 KlMcM:~ klausv.zinser$ pip install --upgrade pip

 DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 
 2020. Please upgrade your Python as Python 2.7 won't be maintained after 
 that date. A future version of pip will drop support for Python 2.7. More 
 details about Python 2 support in pip, can be found at 
 https://pip.pypa.io/en/latest/development/release-process/#python-2-support

 Requirement already up-to-date: pip in 
 /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
  
 (19.2.3)

 KlMcM:~ klausv.zinser$ py4web-start apps

 -bash: py4web-start: command not found
 Neither ./py4web-start apps or py4web-start apps was working. 

 When reviewing what I had done before to install and what I 
 uninstalled: python3 -m pip uninstall py4web  
 I went for workflow 4) from source and install (as I had done this 
 before). 
 That was working,

 I don't want