--- /dev/null
+"""\r
+gc.get_referrers() can be used to see objects before they are fully built.\r
+\r
+Note that this is only an example. There are many ways to crash Python\r
+by using gc.get_referrers(), as well as many extension modules (even\r
+when they are using perfectly documented patterns to build objects).\r
+\r
+Identifying and removing all places that expose to the GC a\r
+partially-built object is a long-term project. A patch was proposed on\r
+SF specifically for this example but I consider fixing just this single\r
+example a bit pointless (#1517042).\r
+\r
+A fix would include a whole-scale code review, possibly with an API\r
+change to decouple object creation and GC registration, and according\r
+fixes to the documentation for extension module writers. It's unlikely\r
+to happen, though. So this is currently classified as\r
+"gc.get_referrers() is dangerous, use only for debugging".\r
+"""\r
+\r
+import gc\r
+\r
+\r
+def g():\r
+ marker = object()\r
+ yield marker\r
+ # now the marker is in the tuple being constructed\r
+ [tup] = [x for x in gc.get_referrers(marker) if type(x) is tuple]\r
+ print tup\r
+ print tup[1]\r
+\r
+\r
+tuple(g())\r