Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
cython class inheritance with python threading #2834
I have this code in python to change to Cython -> to C
As we know Python threads are threading.Thread (contrary to Cython threads)
*I cannot do cdef class Foo(): because it inherits from threading.Thread which is Python, not the Cython parallelism concept
Inside the init function, I have dozens of variables that I have to convert to cdef
Eventually I cannot just type cdef int x,y,z,...., because of the rule in the language basics ""When subclassing an extension type with a Python class, def methods can override cpdef methods but not cdef methods:""
Is this still under development?
Instead of subclassing
import threading cpdef my_task(int threadid, bytes name, int counter): cdef: char* cname float some_float # coerce to C values cname = name with nogil: # do the hard work here task = threading.Thread(target=my_task, args=(1, b"foo", 0)) task.start() print(1)
Alternatively, you subclass
Cython itself does not have its own threading implementation. It allows you to use OpenMP, a compiler feature, or an external C threading library, which is essentially a feature of your operating system. It exposes the Python C-API for threads as well, but these are not nearly as expressive an abstraction as the Python-level interface, and lack fundamental components like a GIL-less thread-safe collection (e.g.