Re: [Python-Dev] Removing the GIL (Me, not you!)

2007-09-15 Thread Justin Tulloss
I'm not sure I understand entirely what you're saying, but it sounds like
you want multiple reference counts. A reference count per thread might not
be a bad idea, but I can't think of how it would work without locks. If
every object has an array of reference counts, then the GC would need to
lock that array to check to see if they're all 0. That means the
incref/decref operations would need to acquire this lock or risk messing up
the GC.

Perhaps you could have something where you have a reference count per thread
and then a thread count per object. Then you would only need to lock the
thread count for the first and last reference a thread makes to an object.
Once there are no threads referencing and object, its obviously safe for
cleanup. Of course, I'm not convinced atomic ops are really so expensive you
can't have every thread doing it at once, but Adam says that the caches will
be thrashed if we have a bunch of threads continuously updating the same
memory address. I can see the possibility. Perhaps once we have a version
that actually demonstrates this thrashing, we can alleviate it with some
sort of multiple reference count scheme.

Justin

On 9/13/07, Tennessee Leeuwenburg <[EMAIL PROTECTED]> wrote:
>
> Pardon me for talking with no experience in such matters, but...
>
> Okay, incrementing a reference counter is atomic, therefore the cheapest
> possible operation. Is it possible to keep reference counting atomic in a
> multi-thread model?
>
> Could you do the following... let's consider two threads, "A" and "B".
> Each time an object is created, a reference count is created in both "A" and
> "B". Let's suppose "A" has a real reference and "B" has no reference really.
> Couldn't the GC check two reference registers for a reference count? The
> object would then be cleaned up only if both registers were 0.
>
> To exploit multiple CPUs, you could have two persistent Python processes
> on each CPU with its own mini-GIL. Object creation would then involve a call
> to each process to create the reference and GC would involve checking each
> process to see what their count is. However, it would mean that within each
> process, threads could create additional references or remove references in
> an atomic way.
>
> In a single-CPU system, this would be the same cost as currently, since I
> think that situation would devolve to having just one place to check for
> references. This seems to mean that it is the case that it would be no more
> expensive for a single-CPU system.
>
> In a two-CPU system, I'm no expertise on the actual call overheads of
> object creation and garbage collection, but logically it would double the
> effort of object creation and destruction (all such operations now need to
> occur on both processes) but would keep reference increments and decrements
> atomic.
>
> Once again, I'm really sorry if I'm completely off-base since I have never
> done any actual coding in this area, but I thought I'd make the suggestion
> just in case it happened to have relevance.
>
> Thanks,
> -Tennessee
>
> ___
> Python-Dev mailing list
> [email protected]
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> http://mail.python.org/mailman/options/python-dev/tulloss2%40uiuc.edu
>
>
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


[Python-Dev] How to pickle class derived from c++ extension

2007-09-15 Thread Martin Drautzburg
I understand that I can picke an extension class written in C/C++ by providing 
a __reduce__() method along with __getstate__()/__setstate__(). While I still 
havent gotten this to work, my main question is:

How could I possibly pickle an object of a  python class which is derived from 
the C++ extension?

It seems that I can define 

>>> class Bar(list):
...  pass

and add more attributes

>>> l=Bar()
>>> l.x=11

and __reduce__() will show the "x" attribute

>>> l.__reduce__()
(, (, 
, []), {'x': 11})

But this does not seem to work with my extension class Foo. I defined a 
__getstate__() method and __reduce__() indeed shows me some state.  But if I 
create a derived class Bar on the Python side and an object bar as an 
instance of that class, and add an "x" attribute to that bar object, then 
__reduce__ing that object shows nothing about the "x" attribute.

This is in a way undestandable, as __reduce__() eventually just calls 
__getstate__() and the only implementation it can find is in my Foo extension 
class, which knows nothing abpout the Bar derived class let alone its "x" 
attribute.

I would like to have __reduce__() do it the pyhon way as far as it cat get, 
and then call some magic method of my C++ class to pickle the "C++ part" of 
an object. Is there a way to achieve this? The "list" class seems to have 
something that my Foo class does not have. What is this?

Or of course if there is a better way, to picke objects of classes which are 
derived from C++ extensions I'd be happy to hear about it.


___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] How to pickle class derived from c++ extension

2007-09-15 Thread Aahz
On Fri, Sep 14, 2007, Martin Drautzburg wrote:
>
> I understand that I can picke an extension class written
> in C/C++ by providing a __reduce__() method along with
> __getstate__()/__setstate__(). While I still havent gotten this to
> work, my main question is:
>
> How could I possibly pickle an object of a python class which is
> derived from the C++ extension?

python-dev is not an appropriate place to ask questions about writing
your own applications.  I suggest the C++-sig or capi-sig lists or the
comp.lang.python newsgroup.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

The best way to get information on Usenet is not to ask a question, but
to post the wrong information.
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


[Python-Dev] Eric Raymond account on bug tracker locked

2007-09-15 Thread Paul Dubois
Eric Raymond (esr)'s account on bugs.python.org has been misused. Since this
may mean that his password on sf.net is also compromised, I cannot trust
that address to notify him. I have changed the password to prevent further
mischief. If someone knows a bona-fide way to contact him let me know it and
I'll inform him, if he doesn't see this himself.
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com