100% CPU Usage when a tcp client is disconnected

Hrvoje Niksic hniksic at xemacs.org
Thu Nov 22 16:39:46 CET 2007

Tzury Bar Yochay <Afro.Systems at gmail.com> writes:

> The following is a code I am using for a simple tcp echo server.
> When I run it and then connect to it (with Telnet for example) if I
> shout down the telnet the CPU tops 100% of usage and saty there
> forever.  Can one tell what am I doing wrong?

If you shut down telnet, self.request.recv(1024) returns an empty
string, meaning EOF, and you start inflooping.

>     def handle(self):
>         while 1:
>             data = self.request.recv(1024)
>             self.request.send(data)
>             if data.strip() == 'bye':      # add: or data == ''
>                 return

More information about the Python-list mailing list