Is Cython a systems programming language?

Hi I have some questions in regards to Cython:

  1. Is it a systems programming language?
  2. How does it do memory management? Does it use CG/Reference counting by default?
  3. Can I convert a normal python program into cython instead?
  4. Does it work with Android, especially if I used DearPythonGui?
  5. Are there any great complete game engines I can use with Cython?

I think you’re better off asking on the Cython mailing list, or just looking at their wiki. This is a CPython forum, not a Cython forum :slight_smile:

Ah right my mistake :slight_smile:

What is the difference between Cython and CPython?

Systems languages tend to operate very close to the hardware, with
little abstraction. Applications languages tend to be more abstract and
operate at a higher level. Cython straddles those two worlds, so it is
hard to classify as a systems or applications language, but I think I
would probably class it as more of an applications language.

Regarding memory management:

https://cython.readthedocs.io/en/latest/src/tutorial/memory_allocation.html

I think that you can run most Python programs in Cython with no change
to the source code. You may not get a lot of benefit, but you will get
some. But if you re-write the Python code in Cython, you will get even
more speed benefit.

I believe that you can run Cython generated code on Android. It looks
like DearPythonGUI does not support Android, so I don’t think you will
be able to use it on Android with or without Cython.

I don’t know what you consider a “great complete game engines”, but you
should be able to use it with Kivy.

Disclaimer: I have never used Cython. All my answers came from googling.

CPython is a Python interpreter and just-in-time compiler
implemented in the C programming language, and is generally
considered the reference implementation of Python.

Cython’s Web site is probably the best place to find out about it,
but the top of the very first page there states:

"Cython is an optimising static compiler for both the Python
programming language and the extended Cython programming
language"

Hope that helps.

You can write programs and libraries compiled from pure C by writing Cython, so in theory anything you can do in C (and a lot of C++) you can also do in Cython. However Cython is mostly geared towards two things: binding existing C programs/libraries with Python, and accelerating compute-intensive functions.

I wouldn’t recommend Cython for systems programming, as other users won’t be familiar with it, and all library documentation, examples and tutorials won’t be in Cython.

Because Cython is basically just Pythonic syntax for C (when in nogil mode), the memory management is basically whatever you explicitly declare (malloc) and your compiler does. You should also be able to interface with Android C (and any game framework’s C/C++) libraries with Cython bindings, if there’s a need for Python to be in the mix.

CPython is the most popular “distribution” (implementation etc) of Python, not what I think you’re talking about.

1 Like

I don’t think that CPython is generally considered to be a just-in-time
compiler.

CPython compiles source code to byte-code, not machine code, ahead of
time, then runs it in a virtual machine.

PyPy is a JIT compiler: after it has run code enough to be able to
predict what it will do, it uses a JIT compiler to generate machine code
on the fly. CPython doesn’t do that.

I suppose it depends entirely on your definition of “compiler” as
Wikipedia presently does refer to it in those terms: “CPython can be
defined as both an interpreter and a compiler as it compiles Python
code into bytecode before interpreting it.”

For what it’s worth, GCIDE, WordNet and FOlDoC all suggest a
compiler creates “an assembly language program” (optionally then
assembled into machine code). I would agree with you at least that I
wouldn’t consider CPython bytecode to be a form of assembly
language, but clearly this is a semantic argument on which
reasonable persons can disagree.

It’s not the compiler part that I am disputing. CPython clearly has a
compiler that takes source code and produces byte-code. I agree with you
on that part. That’s what the .pyc files contain, and that’s what the
compile() builtin function does.

What I’m disputing is that CPython is a Just-In-Time compiler.

CPython does compile modules on demand: you don’t have to go through a
separate “compiler” step to produce executable byte-code before you run
a .py file, although you can:

https://docs.python.org/3/library/compileall.html

But compiling modules on demand is not generally considered sufficient
to be a JIT compiler.

Oh, yep sorry, I entirely agree. I was being sloppy. CPython
compiles scripts to bytecode “just in time to execute them” (you
don’t need so separately invoke its compiler), but you’re right that
an actual “just-in-time compiler” is more than merely that.