SocketServer crash on my machine

Syver Enstad syver at NOSPAMcyberwatcher.com
Wed Jun 27 19:21:52 EDT 2001


Hi pythonistas.

I was checking out the the SocketServer example in Mark Lutz rather
excellent book Programming Python 2 edition,
when

('127.0.0.1', 1120) Thu Jun 28 00:54:00 2001
<socket._socketobject instance at 008EEF94>
Exception in thread Thread-1:
Traceback (most recent call last):
  File "d:\devtools\python21\lib\threading.py", line 378, in __bootstrap
    self.run()
  File "d:\devtools\python21\lib\threading.py", line 366, in run
    apply(self.__target, self.__args, self.__kwargs)
  File "d:\devtools\python21\lib\SocketServer.py", line 246, in
finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "d:\devtools\python21\lib\SocketServer.py", line 495, in __init__
    self.handle()
  File "H:\My Documents\Kode\pythonscript\Syver\class-server.py", line 20,
in ha
ndle
    data = self.request.recv(1024)
  File "<string>", line 1, in recv
AttributeError: 'int' object has no attribute 'recv'

happened, or rather it happens everytime I try it. I've even tried it on a
different machine with the ActiveState distro rather than the BeOpen distro
that I am using on my machine.
Is there anyone out there that can successfully run this piece of code and
receive a request.
If anyone cares to test it, run the code below (or the class-client.py from
Mark Lutz'es book) in a shell window and popup a browser to
http://localhost:50007
You should get the ipaddress of your client and the time, then after 5
seconds the server should crash with the traceback above. Needless to say
this crash happens using the socket module to connect to the server too.

My configuration, BeOpen python 2.1 win32all 140, win2000 pro.
#---------------------------------------------------------------------------
----
import SocketServer
import time

MyHost = ''  # means localhost
MyPort = 50007

def now():
    return time.ctime()

class MyClientHandler(SocketServer.BaseRequestHandler):
    def handle(self):
        print self.client_address, now()
        print self.request
        time.sleep(5)
        while 1:
            data = self.request.recv(1024)
            if not data:
                break
            self.request.send('Echo=>%s at %s' % (data, now()))
        self.request.close()

# make a threaded server
myaddr = (MyHost, MyPort)
server = SocketServer.ThreadingTCPServer(myaddr, MyClientHandler)
server.serve_forever()

#---------------------------------------------------------------------------
----

Is the code itself wrong or is it something wrong with the underlying
implementation, SocketServer or the socket module?
If the code isn't wrong in itself, it might well be the SocketServer as the
examples with the examples with multi threaded sockets but without the
Socket server run just fine on my machine (as well as the single threaded
one's).





More information about the Python-list mailing list