How does python bytecode works?

Devin Jeanpierre jeanpierreda at gmail.com
Sun Jun 17 15:53:37 EDT 2012


On Sun, Jun 17, 2012 at 5:54 AM, gmspro <gmspro at yahoo.com> wrote:
>
> We know python is written in C.
> C is not portable.

Badly written C is not portable. But C is probably the most portable
language on the planet, by virtue of basically every system having a C
compiler backend.

The issue is that a lot of people make nonportable assumptions about
C, and runtimes / OSes / architectures are free to make lots of very
weird decisions.

For example, this code is not strictly universally-compatible C. It is
"portable" in that the changes required to make it run on any system
are trivial, but not in the sense that it should be able to compile
without any changes. (Not unless a cheeky/smart compiler is involved,
anyway).

int main () {
    return 0;
}

Instead of 0, it should "technically" return EXIT_SUCCESS AIUI. Most
people don't care because EXIT_SUCCESS is 0 almost everywhere.

> So how does python work on a webserver like apache/httpd for a python
> website?
> How does the intermediate language communicate with server without
> compiling python code?

Apache is written in C, and can embed CPython. This is easy enough,
because CPython is written in C, and C works well with other C code.
CPython itself can communicate with Python code, because it is
directly responsible for running Python code. So the server
communicates with CPython, and CPython communicates with the Python
code. At no time does Python code ever "directly" touch anything other
than the interpreter.


The bytecode doesn't really have much to do with all this, except that
it is the specific thing that CPython works with.

-- Devin



More information about the Python-list mailing list