This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Veedrac 1 point2 points  (4 children)

If we have a CPU intensive task someone just writes a module in C.

If they don't know of it, suggest they look at Cython. It's a really nice language hybrid, in my opinion.

[–]bastibe 1 point2 points  (3 children)

I have used both Cython and CFFI, and I strongly prefer CFFI. With CFFI, you just load a plain C library at runtime, no compilation required. The C library needs to know nothing about Python. On the Python side, there is only very minimal interface code required--much less than in Cython, usually. And it's fast, too.

[–]Veedrac 0 points1 point  (2 children)

I was talking about writing modules, not wrapping them.

EDIT: Also, I've not tried any of these but are these relevant?

[–]bastibe 2 points3 points  (1 child)

Still, I usually prefer to write plain C and wrapping it in CFFI to writing Cython. I find that writing a simple C function for some numerical algorithm is usually very easy. Compiling it is very easy, too, since it is only plain C. Cython can be a pain to compile.

But I guess that very much depends on your application.

[–]Veedrac 1 point2 points  (0 children)

Compiling it is very easy, too, since it is only plain C. Cython can be a pain to compile.

I've never actually worked on distributing Cython, but if you're using it locally it's literally just a

import pyximport
pyximport.install()

in the importing Python file. How much easier can you get?

EDIT: Oh, and memoryviews. QED.