Comments (8)
Which parts of the code use interned strings?
from cpython.
If you mean _datetimemodule.c
, _datetime_exec()
is a place where assertion errors occur, trying to access dict keys (invalid interned strings).
cpython/Modules/_datetimemodule.c
Lines 6871 to 6918 in a8e5fed
from cpython.
With a debug build, I confirm that an assertion fails at the first PyDict_SetItemString()
call on PyDateTime_DeltaType.tp_dict
, on the second _datetime_exec()
call.
PyObject *d = PyDateTime_DeltaType.tp_dict;
DATETIME_ADD_MACRO(d, "resolution", new_delta(0, 0, 1, 0));
For me, the root issue is that datetime doesn't use heap types but static types.
The symptom is that PyDict_SetItemString() calls PyUnicode_InternInPlace() and so stores interned strings, but interned strings are cleared at Python exit: in Py_Finalize().
Interned strings are just one symptom, but I expect other side effects of reusing static types between two Python executions.
IMO only isolated extensions are safe to be used with the "sub-interpreter" case:
- Use multiple interpreters using sub-interpreters
- Or init/finalize Python multiple times which is a similar but different case
from cpython.
Initialize/Finalize Python multiple time and import datetime each time lead to a memory corruption
That's one way to see the issue. Another way to see is that Python doesn't support datetime with "sub-interpreters" (see my previous message). This issue is about supporting sub-interpreters in datetime :-)
from cpython.
For me, the root issue is that datetime doesn't use heap types but static types.
Yes, but you prevented me from the heap types conversion at #103092 (comment).
Interned strings are just one symptom, but I expect other side effects of reusing static types between two Python executions.
The main and non-isolated subinterpreters share the same module, which avoids redundant initializations. And many objects in a static type are carried over except interned strings. (3.12 needs PR #118618 to carry over static types)
What case are you expecting?
IMO only isolated extensions are safe to be used with the "sub-interpreter" case:
Isolated sub-interpreters are not allowed to load a single-phase init module.
from cpython.
Isolated sub-interpreters are not allowed to load a single-phase init module.
That's also why PEP-687 needs to be completed.
from cpython.
Yes, but you prevented me from the heap types conversion at #103092 (comment).
Right, I am afraid of regression. We should do the conversion in a specific order, step by step, to limit risk and be able to rollback if everything goes wrong.
What case are you expecting?
Objects must not be shared between interpreters, including types. Each interpreter should have its own types to prevent any race condition / concurrent accesses, especially when each interpreter has its own GIL. I don't recall details.
It doesn't matter much. We both agree to isolate the extension.
My proposed plan: #117398 (comment)
from cpython.
Can the isolation be backported to 3.13? Your concern for the sub-interpreters is another specific issue, which is not confirmed on release builds right now.
from cpython.
Related Issues (20)
- ePub error reported at [email protected]
- Avoid creating a StopIteration instance for monitoring HOT 1
- Inconsistent behaviour between `pathlib.PurePath.match` and `glob.glob` HOT 7
- Implement vectorcall for BaseException to optimize creation of exception instances
- Pathlib.Path.symlink_to() returns None instead of a valid object HOT 4
- Add example of overload with default values HOT 7
- Make `IPv{4,6}Address.version` and `max_prefixlen` available on classes, not just instances HOT 3
- Change in `pdb` behavior at exit from post-mortem debugger HOT 3
- dask pyperformance benchmark hangs on win32 HOT 7
- Support formatting UTF-8 email addresses HOT 4
- Incorrect decoding of preamble in email parser
- Add PyFrame_SetLineNumber() for Cython
- Crash in `PyThreadState_DeleteCurrent`: drop_gil: GIL is not locked (free-threading) HOT 3
- "thread sanitizer" (tsan) CI job is hanging HOT 2
- test_interpreters Failing Intermittently Under Py_DISABLE_GIL HOT 3
- __file__ for Some Dynamic Extension Modules has a Broken Refcount
- "invalid integer constant expression" compiling pylifecycle.c
- Segfault accessing frame_locals HOT 10
- `nogil` multi-threading is slower than multi-threading with gil for CPU bound HOT 5
- Asymptotically faster `int(string)`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cpython.