alright i made the change and here is the code:

cdef double count(int n) nogil:
    cdef int i, j, k
    cdef double out
    for i from 0 <= i < n:
        for j from 0 <= j < n:
            out = 0
            for k from 0 <= k < n:
                out += k

    return out


def myinterface():
    cdef int n = 10000000
    cdef double out
    out = count(n)
    return out


this compiles but when i test with this python script I hang on the function
call:

import threading
from giltest import myinterface

class NoGil(threading.Thread):

    def __init__(self):
        super(NoGil, self).__init__()

    def run(self):
        a = myinterface()
        print 'non gil', a


class Gil():

    def run(self):
        print 'gil thread'

if __name__=='__main__':
    a = NoGil()
    b = Gil()
    a.start()
    b.run()
    raw_input()



i presume this is because myinterface() doesn't release the gil, and thus
waits for count() to return.

How do I work this so that I can run a c-function outside the gil and thus
make use of the multi-cores on my machine?

Thanks!

Chris


On Wed, May 13, 2009 at 11:58 AM, Chris Colbert <[email protected]> wrote:

> thanks
>
>
> On Wed, May 13, 2009 at 11:48 AM, Dag Sverre Seljebotn <
> [email protected]> wrote:
>
>> Chris Colbert wrote:
>> > I'm trying to test writing extensions that release the gil. This simple
>> > example is failing cython compilation with errors stating that the
>> > count() function requires the gil.
>> >
>> > Can anyone point me in the right direction?
>>
>> http://trac.cython.org/cython_trac/ticket/205
>>
>> A fix is scheduled at "not before the 0.12 release".
>>
>> Until then, you must use the
>>
>> for i from 0 <= i < n:
>>     ...
>>
>> syntax.
>>
>> --
>> Dag Sverre
>> _______________________________________________
>> Cython-dev mailing list
>> [email protected]
>> http://codespeak.net/mailman/listinfo/cython-dev
>>
>
>
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to