Socket being garbage collected too early

Scott Robinson dscottr at bellatlantic.net
Thu Dec 16 18:25:18 EST 2004


I have been having trouble with the garbage collector and sockets.
Unfortunately, google keeps telling me that the problem is the garbage
collector ignoring dead (closed?) sockets instead of removing live
ones.  My problem is


	x.sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
	do_stuff(x.sock)


def do_stuff(sock):
	sock_list.append(sock)


once do_stuff finishes, x.sock disappears, and I can only believe it
is being garbage collected.  I'd like to hear the standard means for
avoiding this issue (gc appears to have only the interface to declare
something garbage, not to declare something not garbage).

Scott Robinson




More information about the Python-list mailing list