[Python-Dev] Sandboxed Threads in Python

Adam Olsen rhamph at gmail.com
Sat Oct 8 14:29:25 CEST 2005

On 10/7/05, Phillip J. Eby <pje at telecommunity.com> wrote:
> At 07:17 PM 10/7/2005 -0600, Adam Olsen wrote:
> >On 10/7/05, Phillip J. Eby <pje at telecommunity.com> wrote:
> > > Note that implementing a root-based GC for Python is non-trivial, since
> > > extension modules can store pointers to PyObjects anywhere they
> > > like.  Further, many Python objects don't even support being tracked by the
> > > current cycle collector.
> > >
> > > So, changing this would probably require a lot of C extensions to be
> > > rewritten to support the needed API changes for the new garbage collection
> > > strategy.
> >
> >They only need to be rewritten if you want them to provide an
> >immutable type that can be transferred between sandboxes.
> No.  You're missing my point.  If they are able to *reference* these
> objects, then the garbage collector has to know about it, or else it can't
> know when to reclaim them.  Ergo, these objects will leak, or else
> extensions will crash when they refer to the deallocated memory.
> In other words, you can't handwave the whole problem away by assuming "a
> garbage collector".  The garbage collector has to actually be able to work,
> and you haven't specified *how* it can work without changing the C API.

Unfortunately the rammifications of your original statement didn't set
in until well after I sent my reply.  You are right, it does make it
impossible without changing the C API, so that much of the idea is

I wonder if it would be possible to use a wrapper around the immutable
type instead.. something to ponder anyway.

> >I was aware that weakrefs needed some special handling (I just forgot
> >to mention it), but I didn't know it was used by subclassing.
> >Unfortunately I don't know what purpose it serves so I can't
> >contemplate how to deal with it.
> It allows changes to a supertype's C-level slots to propagate to subclasses.

I see.  Well, I would have required the supertype to be immutable, so
there couldn't be any changes to the C-level slots.

Adam Olsen, aka Rhamphoryncus

More information about the Python-Dev mailing list