1,406 questions
1
vote
0
answers
152
views
What is the documented behaviour (if any) when someone imports `pkg.__init__[ as pkg]` instead of `import pkg`?
To be clear, I'm not suggesting anyone actually should import pkg.__init__ directly. This is to understand potential pitfalls if someone decides to convert a module-only distribution into a package, ...
0
votes
0
answers
55
views
undefined symbol: PyObject_SelfIter while using CPython C API [duplicate]
I want to use CPython C API but still got this
[component_container-1] Traceback (most recent call last):
[component_container-1] File "/usr/local/lib/python3.10/dist-packages/numpy/core/...
1
vote
0
answers
40
views
try to add keyword to python's pass_stmt like book cpython internals
I am trying book cpython internals's example: cpython internals ,you can find it at the page 72, an example that add keyword proceed to pass statement. I am using the newest version of cpython(3.14)...
2
votes
0
answers
122
views
Parallel Random Number Generation in GIL-Free Python
I am doing a reinforcement learning simulation in Python that involves running many episodes and updating the weights of the agent per episode. To speed up the process, I wish to run parallel ...
0
votes
0
answers
33
views
Get variable in a CpythonScripExecutor step in Pentaho
I’m trying of get a variable value in a CpythonScriptExecutor step in pentaho spoon but i don’t know how to do that.
I’ve tried with getVariable(“My_var”, “default_value”) , os.getenv(…) and ${My_var} ...
0
votes
1
answer
66
views
Py_FinalizeEx does not clean up everything when rerun of import openai script
I am coding with CPython library and embedded Python into my C++ program. I use Python to run scripts and call Py_Initialize and Py_FinalizeEx per run.
It works fine until I try to import openai in ...
1
vote
0
answers
71
views
Multiprocessing not working with cythonize project
So for the last couple of hours I was trying to figure out a specific issue with multiprocessing when I cythonize my project and have it consist of only .pyd files. The reason I do this is because I ...
0
votes
1
answer
66
views
Can a simple mutex pthread_mutex be a replacement for GIL in a multithreaded Python C extension?
Can a simple mutex pthread_mutex be a replacement for GIL in a multithreaded Python C extension? For eg: if I put mutex locks around Py_INCREF or PyMem_Alloc, would that suffice?
Tried using the GIL, ...
1
vote
0
answers
57
views
Interpretation of the result of an expression
Most Python textbooks and introductory tutorials I have seen say that
The result of every expression is some object.
But I have also seen several Python sources that say that
The result of every ...
1
vote
1
answer
142
views
Create instance of a imported python class with C API
I want to create an instance of a Python class with the C API.
My specific use case is the PySerial Object. My Python code would be:
import serial
test = serial.Serial()
I couldn't find any clue or ...
-1
votes
2
answers
119
views
Why will a syntax error prevent Python from running preceding lines? [duplicate]
Why is the CPython interpreter not executing the previous statements if an EOL syntax error occurs in a later line? I thought that an interpreter is supposed to execute all the statements in a file ...
-1
votes
1
answer
104
views
Py_Initialize return No module named 'encoding'
I tried to use CPython in my c++ project, but after running Py_Initialize i got error like below. I'm using python venv, and the initialization code is simple as
class PyRuntime {
public:
...
1
vote
1
answer
2k
views
Libexpat Vulnerabilities exists in python:3.11-slim Docker Image
There are three vulnerabilities: CVE-2024-45490, CVE-2024-45491 and CVE-2024-45492).
It looks, these vulnerabilities get fixed as part of https://github.com/python/cpython/issues/123678
But when I ...
1
vote
1
answer
186
views
Python Asyncio source code analysis: Why does `_get_running_loop` in Python execute the C implementation instead of the Python one?
I've been exploring the async source code and noticed that the function _get_running_loop() is defined both in Python and has a note stating it's implemented in C (in _asynciomodule.c).
# python3.11/...
0
votes
1
answer
86
views
How to Pass Extra Data to Callback Functions in Python C API?
I'm working on integrating C code with Python using the Python C API, and I need to register callback functions with additional data. Specifically, I want to pass extra data to my callback function so ...
5
votes
2
answers
2k
views
What caused Python 3.13-0b3 ( compiled with GIL disabled ) be slower than 3.12.0?
I did a simple performance test on python 3.12.0 against python 3.13.0b3 compiled with a --disable-gil flag. The program executes calculations of a Fibonacci sequence using ThreadPoolExecutor or ...
0
votes
1
answer
70
views
Create a PyObject with a pointer to a C function
Let's say I have this Python function:
def foo(bar):
bar()
And this C function
void bar() {
}
How can I create a PyObject with Python C API that holds a pointer to bar function so I can call the ...
2
votes
1
answer
115
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 ...
0
votes
1
answer
172
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 ...
-3
votes
1
answer
74
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 ...
0
votes
1
answer
48
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
0
answers
46
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 ...
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
572
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
89
views
Python C extensions - Can't put float into array
I'm learning C and trying to write an extension to convert COO sparse data to a dense array. (I know SciPy can do it.) But I'm stuck. I can declare the integers for the 2D pointer into the array, ...