Am 26.06.2014 um 13:34 schrieb Stefan Behnel <
stef...@behnel.de>:
> Gregor Thalhammer, 26.06.2014 13:21:
>> I experience some problems with my wrapper for AMDs open source GPU FFT
>> library (clFFT),
https://github.com/geggo/gpyfft It seems that the
>> clFFT library does not like to be initialized and released repeatedly.
>> Therefor I would like to change my cython extension class (GpyFFT),
>> which wraps access to the C library, to a singleton class. Some nice
>> recipes I found for Python singletons that redefine __new__, seem not to
>> work with cython, it refuses to compile ('use __cinit__ instead'). Can
>> somebody recommend a best practice approach to realize a singleton class
>> with cython?
>
> Why is it linked to a class and not the module? If reinitialisation is not
> supported, then just initialise it globally, either on module import or on
> first use of the library.
Thanks for the advice. That reinitializing is not possible is an experimental finding (after writing the wrapper), and possibly not intended. At initialization of the library you can define some configuration settings, therefor a class based approach seemed more suitable for me. If you are able to set options only once, that feels like a broken design.
I agree that linking the lifetime of the library to the extension module is probably the best solution, but I am looking for an alternative, that does not require changes to existing code using this wrapper.
>
> How do you know when to do the cleanup? Wouldn't that best be done by an
> atexit callback?
At the moment cleanup is done in __dealloc__ of the object wrapping the library (with Cython.Compiler.Options.generate_cleanup_code = 2)
Thanks for the hint, I have been using `from Cython.Distutils import build_ext`.
> Stefan
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups "cython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
cython-users...@googlegroups.com.
> For more options, visit
https://groups.google.com/d/optout.