Threads for a newbe

Diez B. Roggisch deets_noospaam at web.de
Wed Dec 17 07:32:56 EST 2003


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




More information about the Python-list mailing list