FAQ
We know python is written in C.
C is not portable.
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?
Or how does python interpreted code work with webserver for python based websites?

Please elaborate/explain this topic with example.

Thanks.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120617/068ecea2/attachment-0001.html>

Search Discussions

  • Kev Dwyer at Jun 17, 2012 at 10:41 am

    gmspro wrote:

    We know python is written in C.
    C is not portable.
    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? Or how does python interpreted code work
    with webserver for python based websites?

    Please elaborate/explain this topic with example.

    Thanks.
    http://en.wikipedia.org/wiki/Bytecode
  • Terry Reedy at Jun 17, 2012 at 6:10 pm

    On 6/17/2012 5:54 AM, gmspro wrote:
    We know python is written in C.
    Nope. The CPython Python interpreter is written in (as portable as
    possible) C. The Jython, IronPython, and PyPy Python interpreters are
    written in Jave, C#, and Python respectively. Each compiles Python to
    something different. I presume each (normally) saves the compiled form
    until the source changes. CPython compiles to CPython-specific bytecode.
    It saves the bytecode as a .pyc file in a .__cache__ subdirectory (in 3.2+).
    C is not portable.
    Yes it is (mostly). CPython has been compilied, with minor adjustments,
    on numerous (>20) systems.
    So how does python work on a webserver like apache/httpd for a python
    website?
    The website has a Python interpreter.
    How does the intermediate language communicate with server without
    compiling python code?
    The Python interpreter of the website *does* compile Python code to
    whatever it compiles to.

    --
    Terry Jan Reedy
  • Devin Jeanpierre at Jun 17, 2012 at 7:53 pm

    On Sun, Jun 17, 2012 at 5:54 AM, gmspro 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
  • Kushal Kumaran at Jun 18, 2012 at 6:08 am

    On Mon, Jun 18, 2012 at 1:23 AM, Devin Jeanpierre wrote:
    On Sun, Jun 17, 2012 at 5:54 AM, gmspro 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.
    In the interests of pedantry, I will point out that the C standard
    requires implementation to treat both 0 and EXIT_SUCCESS to be treated
    as successful exits. The implementation must translate this to
    whatever the environment treats as successful termination of the
    program. Ref: specification of the exit(int) function.
    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.
    --
    regards,
    kushal
  • Dan Stromberg at Jun 17, 2012 at 11:57 pm

    On Sun, Jun 17, 2012 at 2:54 AM, gmspro wrote:

    We know python is written in C.
    Yes, at least CPython is. Of course, java is written in C, as are many
    other languages.

    C is not portable.
    C gives you lots of rope to hang yourself with, but if you use C well, it's
    more portable than anything else, including the "portable" languages (the
    ones that don't give you much rope).

    So how does python work on a webserver like apache/httpd for a python
    website?
    I guess this is kind of like asking how you breathe. Python just gets
    exec'd or dlopen'd or something.

    How does the intermediate language communicate with server without
    compiling python code?
    CPython is to .pyc as java is to .class. They're both byte-compiled. Java
    is more commonly JIT compiled than CPython, but Python in general does
    allow JIT compilation.

    IOW, CPython is compiled, it just doesn't burden the developer with a
    separate compile step.

    Or how does python interpreted code work with webserver for python based
    websites?
    Please see above.

    Please elaborate/explain this topic with example.
    You may get better answers if you get into more specifics about what your
    question really is.
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/python-list/attachments/20120617/49553686/attachment-0001.html>

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedJun 17, '12 at 9:54a
activeJun 18, '12 at 6:08a
posts6
users6
websitepython.org

People

Translate

site design / logo © 2023 Grokbase