Created
November 18, 2010 12:40
-
-
Save sbz/704925 to your computer and use it in GitHub Desktop.
retrieve unassigned objects using gc module in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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