Skip to content

Instantly share code, notes, and snippets.

@sbz
Created November 18, 2010 12:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbz/704925 to your computer and use it in GitHub Desktop.
Save sbz/704925 to your computer and use it in GitHub Desktop.
retrieve unassigned objects using gc module in python
import socket
socket.create_connection(('127.0.0.1', 22))
<socket._socketobject object at 0x9022bc4>
s=socket.create_connection(('127.0.0.1', 22))
import gc
[ i for i in gc.get_objects() if type(i) == type(s) ]
[<socket._socketobject object at 0x9022bc4>, <socket._socketobject object at 0x92a4aac>]
t = [ i for i in gc.get_objects() if type(i) == type(s) ][0]
t
<socket._socketobject object at 0x9022bc4>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment