Forums

appending to a list not working quite right.

I start a list outside all my functions say lst = [] .Every time I click my button the list appends a value of 1, and prints the sum of the list. If I click the button three times my list is lst = [1,1,1] and would print 3. Except for about 10% of the time, the list is suddenly empty and 1 gets appended to a random list (I'm assuming it's the same list just set back to empty). Then when I wait for my print statement it's either the list it's supposed to be or the new incorrect list that is occasionally taking my values. It works fine on my localhost and flask. please any help

Every time you click the button on your web app it sends a request which is processed by a "worker". Your account supports 2 uwsgi workers per web app, so it's very probable that some requests will be processed by one worker, and others by another. If you store the list in some global variable, it is possible that sometimes it's stored in one worker's memory, so you see the list expanding. On your local machine you have one process which handles all your requests, that's why it works. The usual solution for such tasks is to store the persistent values in a database.

Thank you very much. makes total sense