Message75577
[David Lambert]
> > @CFUNCTYPE(c_int, POINTER(c_int), POINTER(c_int))
> > def py_cmp_func(*args):
> > (a,b,) = (t[0] for t in args)
> > print("py_cmp_func", a, b)
> > return a-b
> >
> > qsort(ia,len(ia),sizeof(c_int),py_cmp_func)
[Kevin Watters]
> > As far as I know, the above code will fail randomly in release mode if
> > you have multiple threads running Python, because when ctypes calls out
> > to CFUNCTYPE functions, it releases the GIL.
> >
> > For decorating a python function to give to qsort, maybe you can use
> > PYFUNCTYPE?
Kevin is wrong - the code is perfect! Sure does calling a CFUNCTYPE instance
release the GIL, but ctypes aquires the GIL again before executing the python
code in the wrapped py_cmp_func above.
I guess that using PYFUNCTYPE instead would possibly crash because the call to
'qsort' releases the GIL, and the PYFUNCTYPE instance assumes the GIL but does not
acquire it.
But I have no time to work on the docs, sorry. |
|
Date |
User |
Action |
Args |
2008-11-06 18:48:31 | theller | set | recipients:
+ theller, georg.brandl, kevinwatters, LambertDW |
2008-11-06 18:48:30 | theller | link | issue4260 messages |
2008-11-06 18:48:30 | theller | create | |
|