How to implement threaded socket.recv() in python?

I know this does not answer your question on how to fix your deadlock problem, however it appears as your use of threads is overhead in your case.

I know this does not answer your question on how to fix your deadlock problem, however it appears as your use of threads is overhead in your case: You can just use one thread in which you use select() to find out which socket has available data and then handle the reported data. Unless the handling takes long or your protocol is more complicated select should be just fine and avoid all threading issues. Have a look at docs.python.org/howto/sockets.html#non-b... for more details.

If the answer is "just one", then use just one thread. Adding another helps you in no way and only complicates your life, as you found out. If the answer is "several", than one way to organize this is indeed to have a thread per socket.

Recv is a blocking operation, which makes a thread an attractive option to organize code. Each thread owns a separate socket and reads from it at its leisure. You should have no problems and deadlocks with this.

Locks are unnecessary as long as no resources are shared. Even if you do share resources (logging, some data store, etc.) don't just use simple locks - Python has higher-level utilities for that like the Queue module.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions