Reference problem

Michael Morrison borlak at
Wed Sep 6 01:01:31 CEST 2000

I know the answer is somewhere right in my face, but this has been driving
me mad for quite some time.  I got around this problem by just doing a deep
copy, but when I ported my code to unix it barfed at the deep copy (worked
beautifully in windows though).

It has to do with sockets.  The accept() function returns a tuple of a new
socket and an address.  The new socket is my problem, I want to add it to a
global list, reference it, add new variables (specifically byte buffers),
etc.  But of course just socket_list.append(newsocket) only makes a
reference to the original one returned by accept().  Like I said, all I have
to do is make a deep copy and it works fine, but unix is crashing on me.

I want the actual socket object in the list. (plain and simple!)

Any help is greatly appreciated, thanks!

btw, heres the unix error, I didn't even bother messing with it because I
figure there's a better solution to this altogether ;-)
Tue Sep  5 09:59:17 2000 Main loop: copy.error (un(shallow)copyable object
of type <type 'socket'>)
Tue Sep  5 09:59:17 2000 ('./', 14, 'main',
('./', 44, 'handle_sockets', 'new_socket(host)')
('./', 62, 'new_socket', 'socket_list.append(copy.copy(sock))')
('/var/tmp/python-root/usr/lib/python1.5/', 72, 'copy', 'raise error,

More information about the Python-list mailing list