threading/forking and IPC

S

Sophia Cao

Hello,

I am seeking a python solution for my project. I am trying to
implement an architecture where there is a server who receives incoming
messages from several clients, then those messages need to be written
to a MySQL database. To avoid too many connections to the database, I
plan to save the incoming messages into a queue, while use a seperate
process/thread to constantly monitoring the queue and storing the
messages to the database. I am not sure wheather I should use
threading or forking and how to implement the sharing of this message
queue.

Thanks a lot for any advice.
 
D

David Wahler

Sophia said:
Hello,

I am seeking a python solution for my project. I am trying to
implement an architecture where there is a server who receives incoming
messages from several clients, then those messages need to be written
to a MySQL database. To avoid too many connections to the database, I
plan to save the incoming messages into a queue, while use a seperate
process/thread to constantly monitoring the queue and storing the
messages to the database. I am not sure wheather I should use
threading or forking and how to implement the sharing of this message
queue.

Thanks a lot for any advice.

If you want to have a shared queue, it's much easier and simpler to use
threading, as it allows you to share data structures between threads.
Python already has a multithreaded queue class -- see
http://docs.python.org/lib/module-Queue.html. Just create a global
Queue object or pass each thread a reference to it, and they can all
share it.

-- David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top