views:

56

answers:

1

Hi all,

I'm writing a small multithreaded client-side python application that contains a small webserver (only serves page to the localhost) and a daemon. The webserver loads and puts data into a persistent "datastore", and the daemon processes this data, modifies it and adds some more. It should also takes care of the synchronization with the disk.

I'd like to avoid complicated external things like SQL or other databases as much as possible.

What are good and simple ways to design the datastore? Bonus points if your solution uses only standard python.

A: 

What you're seeking isn't too Python specific, because AFAIU you want to communicate between two different processes, which are only incidentally written in Python. If this indeed is your problem, you should look for a general solution, not a Python-specific one.

I think that a simple No-SQL key-value datastore such as Redis, for example, could be a very nice solution for your situation. Contrary to "complicated" using a tool designed specifically for such a purpose will actually make your code simpler.

If you insist on a Python-only solution, then consider using the Python bindings for SQLite which come pre-installed with Python. An SQLite DB can be concurrently used by two processes in a safe manner, as long as your semantics of data access are well defined (i.e. problems you have to solve anyway, the tool nonwithstanding).

Eli Bendersky
I'm talking about a multithreaded application, not multiprocess. And I specifically said I would like to avoid stuff like sqlite or redis. Of course if no one has a good solution to offer, I will go with one of these solutions.Also, I'm aware that what I'm asking isn't too python-specific, but since I know I'm going to write the application in python, I thought I might as well mention it.
static_rtti
@static_rtti - What do you mean by "a small webserver...and a daemon"?? Are you saying that these are actually two threads within a single process (as in deamon = a daemonized thread, not a daemonized process)? And if this is purely a multithreaded solution, then talk of the "datastore" is even more confusing since it suggests that you want to use a file on disk as a means of IPC between two threads. Can you clarify what the actual architecture is?
Jeremy Brown
@static_rtti: your intentions are unclear. Mentioning a daemon makes me think of separate processes. If this is just a few Python threads exchanging information, then just use the `Queue` class
Eli Bendersky