Threads for a newbe

Giraud, Sebastien sebastien.giraud at eds.com
Wed Dec 17 08:41:35 EST 2003


First thx for Your answer :)

So here are my two codes :

The first which doesn't work - And the second which works (at last :) )
I cant say why the first one doesn't work...

In fact you'll see that it's my first time in Python AND in object
programming as well... There are lot's of error (like using variable instead
of using parameters) but I'll rewrite the source when I'll have understood
thread's, socket and object better... Maybe should I have started with an
easier project... ;)

Exceptions, protocol and high lvl user function are still missing. But i
just try to make a socket-server works at first.

If you have any advise or idea I'll be glad to read it :)


-----Message d'origine-----
De : python-list-bounces+sebastien.giraud=eds.com at python.org
[mailto:python-list-bounces+sebastien.giraud=eds.com at python.org] De la part
de Diez B. Roggisch
Envoyé : mercredi 17 décembre 2003 13:33
À : python-list at python.org
Objet : Re: Threads for a newbe


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
-- 
http://mail.python.org/mailman/listinfo/python-list

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Server0.0.1.py
Type: application/octet-stream
Size: 3098 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20031217/4ea7547e/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Server0.0.2.py
Type: application/octet-stream
Size: 3003 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20031217/4ea7547e/attachment-0001.obj>


More information about the Python-list mailing list