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
1,389
questions
0
votes
0
answers
18
views
Spyder console: "_" stops taking last result after being assigned to
I find it useful for _ to contain the value fo the last result. However, I sometimes want to use _ to suppress the printing of the return argument of a function call. Unfortunately, once _ has been ...
2
votes
1
answer
57
views
Suppress stdout message from C/C++ library
I am attempting to suppress a message that is printed to stdout by a library implemented in C.
My specific usecase is OpenCV, so I will use it for the MCVE below. The estimateChessboardSharpness ...
3
votes
0
answers
60
views
AsyncIO CPython hangs with 100% CPU usage
Our Python application is hanging on these 2 particular machines after 10-20 minutes of use. Htop shows 100% CPU usage. I used Pystack to get the stack trace of the running process. The Python side of ...
0
votes
1
answer
40
views
CPython: what happens when the take_gil function calls the drop_gil function
I'm using perf probes to profile the GIL contention in a multithreaded Python application and I find sequences where the take_gil function calls drop_gil as shown in the following perf script dump of ...
0
votes
2
answers
61
views
Definition of the term "value of an object" in CPython
Is it possible to give a formal definition of the term "value of an object" in CPython? After briefly reading some reference articles and Python tutorials, I came to the conclusion that in ...
-3
votes
1
answer
57
views
Parsing a source code with just one digit
Could some please walk me through, how CPython parses a file contain just one character 1?
In particular, why ast.parse("3") returns ...Expr(...)... as (I believe) Python's source code is a ...
1
vote
0
answers
52
views
How to spawn a child process in a python-embedded frozen application?
As far as I know, in python multiprocessing module, the entry function of a child process is the function: multiprocessing.spawn.spawn_main.
According to the following function (multiprocessing.spawn....
0
votes
1
answer
46
views
Python KeyError in x.get("key") [closed]
This is a weird error I am seeing in a log file in python.
import traceback
mat = [{"a": 1, "b": 2}, {"a": 3, "b": 4}]
def fun(a, b, c):
if c is None:
...
1
vote
1
answer
47
views
Python CFFI `<cdata>` data pointer replace from C land - is it safe?
I am trying to use CFFI to create a python C extension.
Suppose I have the following C code:
void freeSomeType(SomeType_t **ptr)
{
free(*ptr);
*ptr = NULL;
}
void func(SomeType_t **ptr)
{
...
1
vote
0
answers
38
views
How to get Python buffer format string from C struct - PEP 3118
I want to know what would be the "thing" generating/inferring what a C struct's "buffer format string" should be, according to PEP 3118.
E.g. if I have some cython code that ...
-3
votes
1
answer
78
views
Why does CPython implement GIL and V8 does not?
I'm seeking insights about CPython's decision to utilize the GIL compared to V8, the JavaScript engine or others that don’t.
While I understand that no language can excel in all aspects, I'm intrigued ...
49
votes
1
answer
2k
views
Why does `dict(id=1, **{'id': 2})` sometimes raise `KeyError: 'id'` instead of a TypeError?
Normally, if you try to pass multiple values for the same keyword argument, you get a TypeError:
In [1]: dict(id=1, **{'id': 2})
------------------------------------------------------------------------...
0
votes
1
answer
84
views
Python Certificate error during TLS handshake to gmail SMTP server
I write a client program which tries to send mail to Gmail SMTP server by smtplib and ssl.SSLContext objects, but get an error when loading a cert PEM file during TLS handshake :
import ssl, smtplib, ...
0
votes
1
answer
164
views
Failure to install python-javabridge: How does pip work differently between Python 3.10 and 3.11?
I am trying to install python-javabridge (GitHub link) in order to set up a Java virtual machine to house libraries for different file formats that Python can subsequently refer to. However, the ...
0
votes
0
answers
75
views
Adding a New Operator to CPython 3.9 Fails to Recognize Syntax in Python
I'm following the CPython internals guide from Chapter 7.5 on adding an operator. The guide uses the example of the "almost equal" operator (~=). Despite following the prescribed steps and ...