Questions tagged [cpython]

The reference implementation of the Python programming language. Use this tag for questions specific to this implementation, general Python questions should just be tagged with "python".

CPython is the default and most widely used implementation of the programming language. It is written in C.

In addition to CPython, there are several other production-quality Python implementations: , a JIT-compiler. , written in Java and , which is written for the Common Language Runtime. There are also several experimental implementations.

CPython is a bytecode interpreter. It has a foreign function interface with several languages including C, in which one must explicitly write bindings in a language other than Python.

See also

1358 questions
9
votes
1 answer

How can asyncio ever not be thread safe considering the GIL?

The asyncio docs read: Most asyncio objects are not thread safe. You should only worry if you access objects outside the event loop. Could someone explain this or give an example of how misuse of asyncio can cause an unsynchronized write to an…
9
votes
1 answer

Compiling cpython code on Ubuntu 16.04

I was the following the instructions on the official cpython code link here. I did a hg update 3.5 and then did the following. sudo apt-get build-dep python3.5 But it is throwing up an error stating the statements listed below: Reading package…
Annapoornima Koppad
  • 1,376
  • 1
  • 17
  • 30
9
votes
1 answer

Why is there different behaviour from getpwuid and getgrgid?

In Python 2.7, 3.4 and 3.5, grp.getgrgid is capable of accepting a string: from grp import getgrgid print(getgrgid('0')) However, pwd.getpwuid can't do the same: from pwd import getpwuid print(getpwuid('0')) Traceback (most recent call last): …
Simon Fraser
  • 2,758
  • 18
  • 25
9
votes
8 answers

CPython vs. Jython vs. IronPython for cross-platform GUI development

I'm thinking of making some kind of experimental IDE for digital hardware design. So I can't decide witch platform to choose. I'm going to have text-editor with syntax highlighting, some vector graphics and lots of tabbed windows. My goals: 1. to…
Vladimir Keleshev
  • 13,753
  • 17
  • 64
  • 93
9
votes
4 answers

ImportError: No module named clr when using CPython of python.org

I'm writing C++ code which should invoke python scripts underneath. For this purpose I use cpython of python.org. Some of the python scripts execute .net code with help of python for .net and when it comes to .net all this fails. I tried to build…
y_d
  • 91
  • 1
  • 1
  • 3
9
votes
3 answers

Why is the destructor called when the CPython garbage collector is disabled?

I'm trying to understand the internals of the CPython garbage collector, specifically when the destructor is called. So far, the behavior is intuitive, but the following case trips me up: Disable the GC. Create an object, then remove a reference to…
Frederik
  • 14,156
  • 10
  • 45
  • 53
9
votes
2 answers

How do I control the module/name of a cython cdef class?

I'm using cython to expose a C++ library to python, by putting all the wrapper objects and functions in an internal module _pydynd, then exposing these through a different python module. I would like to control the name of the module and class that…
mwiebe
  • 275
  • 1
  • 7
9
votes
2 answers

CPython string addition optimisation failure case

The Question Why, in CPython, does def add_string(n): s = '' for _ in range(n): s += ' ' take linear time, but def add_string_in_list(n): l = [''] for _ in range(n): l[0] += ' ' take quadratic…
Veedrac
  • 58,273
  • 15
  • 112
  • 169
9
votes
2 answers

Python C Module - Malloc fails in specific version of Python

I'm writing a Python module to perform IO on a O_DIRECT context. One of the limitations of O_DIRECT is you must read into a buffer aligned on a 4096 byte boundary for 2.4 and 2.5 kernels, and 2.6 and up will accept any multiple of 512. The obvious…
bradfier
  • 91
  • 1
  • 4
9
votes
6 answers

Overriding the newline generation behaviour of Python's print statement

I have a bunch of legacy code for encoding raw emails that contains a lot of print statements such as print >>f, "Content-Type: text/plain" This is all well and good for emails, but we're now leveraging the same code for outputting HTTP request.…
brotchie
  • 491
  • 4
  • 10
9
votes
2 answers

Python: GIL context - switching

So, I generally have a pretty good understanding of how the Global Interpreter Lock (GIL) in Python works. Essentially, while the interpreter is running, one thread holds the GIL for N ticks (where N can be set using sys.setcheckinterval), at which…
Channel72
  • 24,139
  • 32
  • 108
  • 180
8
votes
1 answer

Why is the float * int multiplication faster than int * float in CPython?

Basically, the expression 0.4 * a is consistently, and surprisingly, significantly faster than a * 0.4. a being an integer. And I have no idea why. I speculated that it is a case of a LOAD_CONST LOAD_FAST bytecode pair being "more specialized" than…
mwo
  • 446
  • 3
  • 9
8
votes
1 answer

Detect argument passing convention of a C library function

With pure Python functions you can pass arguments either by order (e.g. foo(1, 2, 3)) or by name (e.g. foo(a=1, c=3, b=2)). Functions defined in C modules can use either convention. You cannot say range(stop=10, step=2), and so it is with most but…
9000
  • 39,899
  • 9
  • 66
  • 104
8
votes
1 answer

Python >= 3.3 Internal String Representation

I was looking into how Python represents string after PEP 393 and I am not understanding the difference between PyASCIIObject and PyCompactUnicodeObject. My understanding is that strings are represented with the following structures: typedef struct…
Alberto O.
  • 835
  • 1
  • 8
  • 14
8
votes
2 answers

Even though tuples are immutable, they are stored in different addresses in interactive mode. Why?

t = (1,2,3) t1 = (1,2,3) print(id(t)) print(id(t1)) The above lines of code gives the same addresses in script mode in Python, but in interactive mode it outputs different addresses. Can anyone explain the reason for this?
Harsha jk
  • 81
  • 2