Hello,

I'm trying to build a very simple IPC system.  What I have done is
create Data Transfer Objects (DTO) for each item I'd like to send
across the wire.  I am serializing these using cPickle.  I've also
tried using pickle (instead of cPickle), but I get the same response.

Below is the code.  I'll put the rest of my comments after the code

[BEGIN CODE]
#!/usr/bin/python
import SocketServer
import os, sys
newpath = os.path.normpath( os.path.join( __file__, "../../.." ))
sys.path.insert(0, newpath)

from pop.command.UpdateCommand import *
import cPickle

class RequestHandler(SocketServer.StreamRequestHandler):
    "Handles one request to mirror some text."

    def handle(self):
        total_data=[]

        line = True
        while line:
            line = self.rfile.readline().strip()
            total_data.append(line)

        receivedCommand = '\n'.join(total_data)

        newUpdate = cPickle.loads(receivedCommand)
        print type(newUpdate)
        for item in newUpdate.items:
            print str(type(item)) + " with filename: " + item.filename


if __name__ == '__main__':
    import sys
    if len(sys.argv) < 3:
        print 'Usage: %s [hostname] [port number]' % sys.argv[0]
        sys.exit(1)
    hostname = sys.argv[1]
    port = int(sys.argv[2])
    server = SocketServer.ThreadingTCPServer((hostname, port),
RequestHandler)
    server.serve_forever()
[/END CODE]

So I can create the UpdateCommand object on the client, send it across
the wire and I get as far as the line
"newUpdate = cPickle.loads(receivedCommand)",
which when it runs produces the following error:

Traceback (most recent call last):
  File "C:\Python25\lib\SocketServer.py", line 464, in
process_request_thread
    self.finish_request(request, client_address)
  File "C:\Python25\lib\SocketServer.py", line 254, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "C:\Python25\lib\SocketServer.py", line 522, in __init__
    self.handle()
  File "C:\Documents and Settings\dwatrous\My Documents\projects\POP
\svn\pop\lib\server.py", line 29, in handle
    newUpdate = cPickle.loads(receivedCommand)
ImportError: No module named UpdateCommand

I import the module at the top of the file server.py, but it doesn't
throw the ImportError until it tries to unpickle.

Please help with any ideas that you have.
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to