Martin von Loewis
loewis at informatik.hu-berlin.de
Fri Sep 8 22:22:50 CEST 2000
"Michael Morrison" <borlak at home.com> writes:
> 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.
You can't copy file objects. I'm not sure why you want to, either -
just use the one you've got in all places.
If you really want such a functionality, you can use the Unix dup(2)
interface to create a second file handle. You can also use the
posixfile module on top of that, i.e.
pfile = posixfile.fileopen(newsocket)
filecopy = pfile.dup()
As for copying adding variables to a socket object: That won't work,
either. A socket object does not support arbitary attributes, only the
documented ones. Again, wrapping it with a posixfile may be a
solution, but the wrong one - you shall not modify other objects attributes.
More information about the Python-list