Live data from Hacker News

CPython Internals Explained

github.com

11–20 of 54 posts

Re: CPython Internals Explained

#11
post #5

I wish they would just go back to calling it Python, since it’s the Python that everyone knows and uses. No one gets confused over Python the spec and Python the implementation. Every time I see “CPython” i have to double check we’re just talking about Python. I guess they “CPython’ed” back when people thought Jython would take off , and it never did because Java sucks.

Just to name alternatives: Cpython, Pypy, jython, ironpython. Then, there quite a few python-likes out there. I wish they would stay precise.

CPython, pypy, jython are not alternatives.

CPython is Python. The others are attempts.

Re: CPython Internals Explained

#12
post #5

I wish they would just go back to calling it Python, since it’s the Python that everyone knows and uses. No one gets confused over Python the spec and Python the implementation. Every time I see “CPython” i have to double check we’re just talking about Python. I guess they “CPython’ed” back when people thought Jython would take off , and it never did because Java sucks.

Just to name alternatives: Cpython, Pypy, jython, ironpython. Then, there quite a few python-likes out there. I wish they would stay precise.

Yes, but no one is ever talking about pypy or jython implicitly. They are always mentioned by name because they represent It’s a bit like arguing people should start saying “homo sapiens” when referencing “people” for added precision. It may be useful to anthropologists but the rest of us really don’t need that. Similarly, CPython is really only a sensible level of precision in a discussion directly about alternative Python implementations.

(although in this case the original post is about implementation internals so I’d give it a pass)

Re: CPython Internals Explained

#13
post #4

I've been comparing various platforms and discussing them with ChatGPT—for instance, why Python's execution is slower than JavaScript's V8. It claimed this is due to mtechnical debt and the inability to change because libraries like NumPy bypass public interfaces and access data directly. I'm wondering how much of that is true and what is just a hallucination." Btw: JavaScript seems to have similar complexity issues.…

    > Edit: Python has no JIT
There are quite a few JITs:

JIT-compiler for Python https://pypy.org/

Python enhancement proposal for JIT in CPython https://peps.python.org/pep-0744/

And there are several JIT-compilers for various subsets of Python, usually with focus on numerical code and often with GPU support, for example

Numba https://numba.pydata.org/numba-doc/dev/user/jit.html

Taichi Lang https://github.com/taichi-dev/taichi

Re: CPython Internals Explained

#14

Earlier quoted context omitted.

Just to name alternatives: Cpython, Pypy, jython, ironpython. Then, there quite a few python-likes out there. I wish they would stay precise.

Yes, but no one is ever talking about pypy or jython implicitly. They are always mentioned by name because they represent It’s a bit like arguing people should start saying “homo sapiens” when referencing “people” for added precision. It may be useful to anthropologists but the rest of us really don’t need that. Similarly, CPython is really only a sensible level of precision in a discussion directly about alternative…

I like this debate because it triggers everyone’s pragmatic frustration with the philosophy of language.

Are things defined by the dictionary or by everyday experiences?

Re: CPython Internals Explained

#15

Earlier quoted context omitted.

Just to name alternatives: Cpython, Pypy, jython, ironpython. Then, there quite a few python-likes out there. I wish they would stay precise.

Yes, but no one is ever talking about pypy or jython implicitly. They are always mentioned by name because they represent It’s a bit like arguing people should start saying “homo sapiens” when referencing “people” for added precision. It may be useful to anthropologists but the rest of us really don’t need that. Similarly, CPython is really only a sensible level of precision in a discussion directly about alternative…

This seems to be literally looking at the details of the C implementation of a Python interpreter. Exactly specifying the implementation makes sense here. You wouldn't say "how does the C++ compiler work" then look only at gcc.

Re: CPython Internals Explained

#16
vstinner's Python docs; "Unofficial Python Development (Victor's notes) documentation" > Garbage Collector > "Implement the GC protocol in a type": https://pythondev.readthedocs.io/garbage_collector.html#impl...

Python Developer's Guide > "CPython's internals": https://devguide.python.org/internals/index.html

Python/cpython//InternalDocs/README.md > "CPython Internals Documentation": https://github.com/python/cpython/blob/main/InternalDocs/REA...

Re: CPython Internals Explained

#17

Earlier quoted context omitted.

Yes, but no one is ever talking about pypy or jython implicitly. They are always mentioned by name because they represent It’s a bit like arguing people should start saying “homo sapiens” when referencing “people” for added precision. It may be useful to anthropologists but the rest of us really don’t need that. Similarly, CPython is really only a sensible level of precision in a discussion directly about alternative…

This seems to be literally looking at the details of the C implementation of a Python interpreter. Exactly specifying the implementation makes sense here. You wouldn't say "how does the C++ compiler work" then look only at gcc.

c++ / g++ is not comparable because the original c++ reference compilers are not commercially popular today. No one is using Strouvestroups compilers.

CPython is Python. Every time your buddy says “just download python” you are using CPython . There’s no reason to be pedantic.

Re: CPython Internals Explained

#18
post #7
post #4

I've been comparing various platforms and discussing them with ChatGPT—for instance, why Python's execution is slower than JavaScript's V8. It claimed this is due to mtechnical debt and the inability to change because libraries like NumPy bypass public interfaces and access data directly. I'm wondering how much of that is true and what is just a hallucination." Btw: JavaScript seems to have similar complexity issues.…

> Edit: Python has no JIT In 3.14 and up you can enable JIT by setting the env var PYTHON_JIT=1

Who made this JIT? FAcebook?

Re: CPython Internals Explained

#19
post #4

I've been comparing various platforms and discussing them with ChatGPT—for instance, why Python's execution is slower than JavaScript's V8. It claimed this is due to mtechnical debt and the inability to change because libraries like NumPy bypass public interfaces and access data directly. I'm wondering how much of that is true and what is just a hallucination." Btw: JavaScript seems to have similar complexity issues.…

If we are being very pedantic, languages don't have "speed", only implementations do.

Of course in the real life there are de facto implementations and language features give way to better/worse tradeoffs.

With that out of the way, Python is basically the de facto glue language. It is very often used to provide a scripting API over lower level C libraries. To be ergonomic in this function, CPython (the major implementation) exposed some internal details of its execution model, which C libraries can reach into. This makes it very hard to make more aggressive optimizations, as one example a C library can just increase/decrease the reference count of an object. Another design decision (that got some discussion recently) is the GIL (global interpreter lock) that makes python much less competitive than something like Java. (JS also does a single thread of execution, though there are ways around it).

JS has a different use case, so access to the C world doesn't impose such restrictions on it.

Re: CPython Internals Explained

#20

vstinner's Python docs; "Unofficial Python Development (Victor's notes) documentation" > Garbage Collector > "Implement the GC protocol in a type": https://pythondev.readthedocs.io/garbage_collector.html#impl... Python Developer's Guide > "CPython's internals": https://devguide.python.org/internals/index.html Python/cpython//InternalDocs/README.md > "CPython Internals Documentation": https://github.com/python/cpython…

IDK why /InternalDocs/ instead of /Doc/internals/ ? ( `ln -s` works with Mac/Lin/WSL. )

Ideally what's in InternalDocs/ would be built into the docs.python.org docs .

Is it just that markdown support in sphinx is not understood to exist?

Sphinx has native markdown support. Sphinx does not have native MyST Markdown support. To support MyST Markdown in a sphinx-doc project, you must e.g. `pip install myst_parser` and add "myst_parser" to the extensions list in conf.py.

MyST Markdown supports docutils and sphinx RestructuredText roles and directives: https://myst-parser.readthedocs.io/en/latest/syntax/roles-an...

Directive in ReStructuredText .rst:

  .. directivename:: arguments
     :key1: val1
     :key2: val2

   This is
   directive content
Directive in MyST Markdown .md:

  ```{directivename} arguments
  :key1: val1
  :key2: val2
  
  This is
  directive content
  ```
RestructuredText Role, MyST Markdown Role:

  :role-name:`role content`
  {role-name}`role content`
Sphinx resolves reference labels at docs build time, so that references will be replaced with the full relative URL to the path#fragment of the document where they occur; in ReStructuredText and then MyST Markdown:

  .. _label-name:
  (label-name)=

  :ref:`Link title `
  {ref}`Link title `
Post reply on HN