This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Using a storage module on a server that does not support locks etc...
I have just been thinking what would happen if I wanted to use a simple storage/DB that does not support locks etc with something like flask web server vrs just locally. Many more issues to think about than just using it locally, But still, if you have the idea 'first in first served' its not a big leap to think about maybe a queue is the answer. The code here is my first attempt to get something working (faking it ) as a beginner. It's possible this is just handled somehow in these frameworks. What I have done is clunky and I don't understand all I have done. It would be cool to have some sort of test bed written like this, but properly. Maybe you think this does not apply to Pythonista. But i do. Maybe i am trying to re-invent the wheel. I don't mean to. Just at the end of the day, want to know how i can handle muliple writers to a storage device that is designed for single users.
Well i guess this generated as much interest as grass growing :). I had some fun doing it though. I was originally using the update off a ui.View as the MainProcess(). I worked ok, but i had a few little glitches once the threads had finished. I am pretty sure my lack of knowledge of threads and maybe doing something that conflicted with the ui.View update mechanism.
But my question still remains. If I wanted to use a simple single user database like tinydb for a project using flask on a web server, would this be a reason approach given I am ok that the last updater wins so to speak. I understand this is not strictly a Pythonista question, but its still part of the puzzle so to speak. I have often thought about doing a generic voting app in Pythonista, but i still need to be able to do the backend.
Btw, backend I am talking about is not meant for general consumption. So we are not talking about thousands of people trying to hit all at once.
Would be interested if anyone has some insights. But I would like to keep the backend as simple as possible.
mikael last edited by
@Phuket2, do you need a web server, or just a storage backend for your Pythonista app?
@mikael , its all just theory at the moment. I was thinking of trying to do some thing simple. Mind you when you start putting all the pieces together its not as simple as it sounds.
But its ok, I am going to go a head with my plan.
Use flask as the server and tinydb as the backend database. It's going to be a very simple app in terms of data (at least to begin with).
The app is just a voting app. The user will be presented some choices with question and vote. I am goin to flatten of the data so a single json record will contain all the info required for the ui to render.
I will do a local version first then try and get it working on web with flask. I will post once I get my little local thingy running.
But thanks for your reply.
ccc last edited by
- Each user has a unique ID so that you can keep each user's responses separated?
- Do you want to do CRUD (Create, Read, Update, Delete) or do you just want to allow the user to vote once and they can not vote again, change their vote, or delete their vote?
- Do you want the user to be able to see their vote in a read-only fashion in a later session after the session where they voted?
- Do you want users to see the votes of other users? If so, in detail or in summary form?
@ccc , all great(insightful) questions. I had thought of most but not all of them. I am just going to do it my crappy way first. Just local, no server. I did start out with with some relation model. Like owner_id, category_id, this_id etc... It gets too complicated for my poor little brain. So I will just build it up like lego blocks. I am sure its going to look ugly for a while. But ifI try to do more, it will implode and just stop.
Personally I think a little voting app is super cool on many levels. The idea is that the server is just providing a so called restful service using json. Then the client can render based on the json responses. Sounds simple....But so many moving parts.
I have also seen tinydb has an ext i think called tiny record, that supports a transaction. Anyway, i know, what i am saying is a mess and all over the place. But for a single developer a lot of things to do and understand.
But i am trying to but some stuff together.
@ccc, i started a repo even though its not ready for that. It's crap. But just slowly trying to get my head around it.
I am trying to go a little slower and write more concise statements also. Anyway, give me a few more days. I will keep pushing to the repo.
But again for the moment, i am going to dead sh*t simple
mikael last edited by
@Phuket2, reason I was asking was that if you do not really need a web server, you can just use something like persistent PubNub streams and not care about the backend. Also likely to be free for your probable volumes.
And if you need a web page to share results, a simple AWS Lambda function can pull the data from PubNub and return an HTML page (again, probably free).
@mikael, oh i think i see what you mean. I have a PythonAnwhere account for the hosting. I will stick with that to get going.