Threads for a newbe

S

Sebastien GIRAUD

Hello,
First let say that am french and that i'll try to write the best english i can...
I'm a python newbe and have the following problem : I try to create 2 threads in a server program and they seems to block each other.
I use something like this :
start thread waiting for connexion with : server.threadserver = threading.Thread(target = self.__startserver)
then do while 1 :
socket, host = accept(...)
then start a new thread for each new connexion after accept using client.threadclient = threading.Thread(target = self.__receive)
and while 1 :
client.receive()
And here the first thread seems not to work anymore :( . I didn't join threads. Maybe a lock() problem but i don't now how to use the lock() function in Python...
Maybe if someone had a multithread server sample source I could understand what is the issue...
Regards
Seb.
 
D

Diez B. Roggisch

Hi,
i can... I'm a python newbe and have the following problem : I try to
create 2 threads in a server program and they seems to block each other.
I use something like this :
start thread waiting for connexion with : server.threadserver =
threading.Thread(target = self.__startserver) then do while 1 :
socket, host = accept(...)
then start a new thread for each new connexion after accept using
client.threadclient = threading.Thread(target = self.__receive)
and while 1 :
client.receive()
And here the first thread seems not to work anymore :( . I didn't join
threads. Maybe a lock() problem but i don't now how to use the lock()
function in Python... Maybe if someone had a multithread server sample
source I could understand what is the issue...

I recently did implement a socket-server using threads. So if you give me
more actual code, I might be able to help you.

However, I stepped away from that approach and went for twisted - a really
excellent networing framework, which eliminated the need for different
threads. You should really look into that, as just having different threads
sitting on blocking io-descriptors is abusing them (while I have to admit -
its tempting...)

Regards,

Diez
 

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
474,172
Messages
2,570,934
Members
47,478
Latest member
ReginaldVi

Latest Threads

Top