[Stackless] Weakref support for tasklets

Bob Ippolito bob at redivi.com
Thu Jan 29 23:07:23 CET 2004

On Jan 29, 2004, at 4:52 PM, Christian Tismer wrote:

> Bob Ippolito wrote:
> ...
>> You should also consider that one word might not make a difference.  
>> The allocator on Mac OS X, for example, always returns 128bit aligned 
>> pointers as an optimization for the AltiVec unit.  It completely 
>> ignores the low 3 bits of any address, so working with unaligned data 
>> is a chore!
> Har har :)
> More thoughts on this:
> We also *might* consider to introduce another derived
> type which has this feature enabled.
> For the moment, I don't propose that.
> Is it possible to derive a type in Python with weakref
> enabled? That would be a reason to disable it by default
> and to give the user the option.
> ...
>> I'll go ahead and add weakref support to them as well.
> If it is doable from Python, then we don't need to
> enforce it in the implementation. Well, I don't know.

Remember, we are talking about [approximately] sizeof(PyObject*) bytes 
per tasklet/channel here :)

I'm not entirely sure that a derived type is the best solution, because 
it's entirely possible that the code that creates your tasklets is 
logically separate from the code that needs to use them weakly (it is 
in my case, at least).

Either way, unless you use __slots__ without a '__weakref__' then any 
derived-from-python type is weakref-able, but adds more than the 
sizeof(PyObject*) bytes per instance and means that there's more code 
that the developer has to think about and write.  This is a reasonable 
way to add weakref support to file objects (class weakfile(file): 
pass), for example, but I personally think that they should be be 
weakref-able by default (come on, a few bytes per open file?  You'd run 
out of descriptors far before it matters).

Besides, weakref support is a good way to test tasklets and channels to 
make sure they actually do get deallocated at the right time ;)  Adding 
weakref support to channels is another 4 line change, and I have 
already written simple unit tests to make sure that the weak references 
actually work.  I'm going to go ahead and commit it.. if you strongly 
object, then take it out ;)


Stackless mailing list
Stackless at stackless.com

More information about the Stackless mailing list