chunk_id stringlengths 36 36 | source stringclasses 35
values | source_url stringlengths 0 290 | upstream_license stringclasses 1
value | document_id stringlengths 36 36 | chunk_index int64 0 324k | retrieved_at stringclasses 2
values | chunker_version stringclasses 4
values | content_hash stringlengths 15 64 | content stringlengths 50 44.7k | namespace stringclasses 9
values | source_name stringclasses 35
values | raw_text stringlengths 50 44.7k | cleaned_text stringlengths 50 44.7k | tags stringclasses 49
values | collection_name stringclasses 11
values |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
82e4f0b4-fab7-48b4-8f69-1df2d53883dd | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,769 | supabase-export-v2 | c0222333dac164da | structure used for communication between the debugger and the interpreter. The locations of its fields are defined by the ``_Py_DebugOffsets`` structure and include the following:
- ``debugger_script_path``: A fixed-size buffer that holds the full path to a
Python source file (``.py``). This file must be accessible an... | trusted_official_docs | CPython Docs | structure used for communication between the debugger and the interpreter. The locations of its fields are defined by the ``_Py_DebugOffsets`` structure and include the following:
- ``debugger_script_path``: A fixed-size buffer that holds the full path to a
Python source file (``.py``). This file must be accessible an... | structure used for communication between the debugger and the interpreter. The locations of its fields are defined by the ``_Py_DebugOffsets`` structure and include the following:
- ``debugger_script_path``: A fixed-size buffer that holds the full path to a
Python source file (``.py``). This file must be accessible an... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
862d250d-34f9-4b41-9053-2603a02fe7ba | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,729 | supabase-export-v2 | 45f9a7142b3caaca | Reading _Py_DebugOffsets ========================
Once the address of the ``PyRuntime`` structure has been determined, the next
step is to read the ``_Py_DebugOffsets`` structure located at the beginning of
the ``PyRuntime`` block. | trusted_official_docs | CPython Docs | Reading _Py_DebugOffsets ========================
Once the address of the ``PyRuntime`` structure has been determined, the next
step is to read the ``_Py_DebugOffsets`` structure located at the beginning of
the ``PyRuntime`` block. | Reading _Py_DebugOffsets ========================
Once the address of the ``PyRuntime`` structure has been determined, the next
step is to read the ``_Py_DebugOffsets`` structure located at the beginning of
the ``PyRuntime`` block. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
89c0daa6-e16b-4d59-8337-708bd9f87454 | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,747 | supabase-export-v2 | df833ff1bc97b9ec | located in the ``_PyRemoteDebuggerSupport`` structure, which is embedded in a ``PyThreadState`` object. These fields are modified by the debugger to request execution of injected scripts.
The ``PyThreadState`` structure represents a thread running inside a Python
interpreter. It maintains the thread’s evaluation contex... | trusted_official_docs | CPython Docs | located in the ``_PyRemoteDebuggerSupport`` structure, which is embedded in a ``PyThreadState`` object. These fields are modified by the debugger to request execution of injected scripts.
The ``PyThreadState`` structure represents a thread running inside a Python
interpreter. It maintains the thread’s evaluation contex... | located in the ``_PyRemoteDebuggerSupport`` structure, which is embedded in a ``PyThreadState`` object. These fields are modified by the debugger to request execution of injected scripts.
The ``PyThreadState`` structure represents a thread running inside a Python
interpreter. It maintains the thread’s evaluation contex... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8df1001e-8801-4e24-91cc-68d272172990 | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,701 | supabase-export-v2 | 7c8c1511e300a3ab | the offset where that section exists in the file, which can be used to calculate its runtime address when the binary is loaded into memory.
You can read more about the ELF file format in the `ELF specification
<https://en.wikipedia.org/wiki/Executable_and_Linkable_Format>`_. | trusted_official_docs | CPython Docs | the offset where that section exists in the file, which can be used to calculate its runtime address when the binary is loaded into memory.
You can read more about the ELF file format in the `ELF specification
<https://en.wikipedia.org/wiki/Executable_and_Linkable_Format>`_. | the offset where that section exists in the file, which can be used to calculate its runtime address when the binary is loaded into memory.
You can read more about the ELF file format in the `ELF specification
<https://en.wikipedia.org/wiki/Executable_and_Linkable_Format>`_. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8ea188ba-dab1-4254-9999-a7e8682fac2c | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,753 | supabase-export-v2 | 3043e741eb2fe4bf | To locate a thread:
1. Use the offset ``runtime_state.interpreters_head`` to obtain the address of
the first interpreter in the ``PyRuntime`` structure. This is the entry point
to the linked list of active interpreters. | trusted_official_docs | CPython Docs | To locate a thread:
1. Use the offset ``runtime_state.interpreters_head`` to obtain the address of
the first interpreter in the ``PyRuntime`` structure. This is the entry point
to the linked list of active interpreters. | To locate a thread:
1. Use the offset ``runtime_state.interpreters_head`` to obtain the address of
the first interpreter in the ``PyRuntime`` structure. This is the entry point
to the linked list of active interpreters. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
90efb50f-dac0-4074-9c66-ee7437997859 | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,733 | supabase-export-v2 | b70c04ee084ba96d | memory block. Its layout is defined in CPython’s internal headers and stays the same within a given minor version, but may change in major versions.
2. Check that the structure contains valid data: | trusted_official_docs | CPython Docs | memory block. Its layout is defined in CPython’s internal headers and stays the same within a given minor version, but may change in major versions.
2. Check that the structure contains valid data: | memory block. Its layout is defined in CPython’s internal headers and stays the same within a given minor version, but may change in major versions.
2. Check that the structure contains valid data: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
935f0d5d-0534-4544-88fb-33c9cf44e26b | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,669 | supabase-export-v2 | cab439b0f1963188 | .. rubric:: macOS
To attach to another process, you typically need to run your debugging tool
with elevated privileges. This can be done by using ``sudo`` or running as
root. | trusted_official_docs | CPython Docs | .. rubric:: macOS
To attach to another process, you typically need to run your debugging tool
with elevated privileges. This can be done by using ``sudo`` or running as
root. | .. rubric:: macOS
To attach to another process, you typically need to run your debugging tool
with elevated privileges. This can be done by using ``sudo`` or running as
root. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
94973877-50ef-4534-a49d-e95791ce4a9d | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,763 | supabase-export-v2 | 466d6130382003e5 | int, debug_offsets: DebugOffsets, target_tid: int, ) -> int: # Start at threads_head and walk the linked list thread_ptr = read_pointer( pid, interp_addr + debug_offsets.interpreter_state.threads_head )
while thread_ptr:
native_tid_ptr = (
thread_ptr + debug_offsets.thread_state.native_thread_id
)
native_tid = read... | trusted_official_docs | CPython Docs | int, debug_offsets: DebugOffsets, target_tid: int, ) -> int: # Start at threads_head and walk the linked list thread_ptr = read_pointer( pid, interp_addr + debug_offsets.interpreter_state.threads_head )
while thread_ptr:
native_tid_ptr = (
thread_ptr + debug_offsets.thread_state.native_thread_id
)
native_tid = read... | int, debug_offsets: DebugOffsets, target_tid: int, ) -> int: # Start at threads_head and walk the linked list thread_ptr = read_pointer( pid, interp_addr + debug_offsets.interpreter_state.threads_head )
while thread_ptr:
native_tid_ptr = (
thread_ptr + debug_offsets.thread_state.native_thread_id
)
native_tid = read... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
95c5ccc4-0f34-45fa-9a20-de70b832ca5b | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,757 | supabase-export-v2 | 0c63fa0db07fb999 | valid ``PyThreadState`` has been found, its address can be used in later steps of the protocol, such as writing debugger control fields and scheduling execution.
The following is an example implementation that locates the main thread state:: | trusted_official_docs | CPython Docs | valid ``PyThreadState`` has been found, its address can be used in later steps of the protocol, such as writing debugger control fields and scheduling execution.
The following is an example implementation that locates the main thread state:: | valid ``PyThreadState`` has been found, its address can be used in later steps of the protocol, such as writing debugger control fields and scheduling execution.
The following is an example implementation that locates the main thread state:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9757ca4b-57c1-440a-a2ca-f60fb4648421 | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,756 | supabase-export-v2 | 1a784561a4dabf07 | of all thread states. Each ``PyThreadState`` structure contains a ``native_thread_id`` field, which may be compared to a target thread ID to find a specific thread.
4. Once a valid ``PyThreadState`` has been found, its address can be used in
later steps of the protocol, such as writing debugger control fields and
sch... | trusted_official_docs | CPython Docs | of all thread states. Each ``PyThreadState`` structure contains a ``native_thread_id`` field, which may be compared to a target thread ID to find a specific thread.
4. Once a valid ``PyThreadState`` has been found, its address can be used in
later steps of the protocol, such as writing debugger control fields and
sch... | of all thread states. Each ``PyThreadState`` structure contains a ``native_thread_id`` field, which may be compared to a target thread ID to find a specific thread.
4. Once a valid ``PyThreadState`` has been found, its address can be used in
later steps of the protocol, such as writing debugger control fields and
sch... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9ab2a5e1-d6a3-4ba0-bc47-8a358e543724 | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,719 | supabase-export-v2 | 188f1da4d800c13e | This section contains the ``PyRuntime`` structure. 4. Retrieve the section’s relative virtual address (RVA) and add it to the base address of the module.
The following is an example implementation:: | trusted_official_docs | CPython Docs | This section contains the ``PyRuntime`` structure. 4. Retrieve the section’s relative virtual address (RVA) and add it to the base address of the module.
The following is an example implementation:: | This section contains the ``PyRuntime`` structure. 4. Retrieve the section’s relative virtual address (RVA) and add it to the base address of the module.
The following is an example implementation:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9b9a206b-0800-4295-a1be-ad8c02a92f0b | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,772 | supabase-export-v2 | dcac63396a0140d4 | the interpreter during execution. Setting bit 5 (``_PY_EVAL_PLEASE_STOP_BIT``, value ``1U << 5``) in this field causes the interpreter to pause and check for debugger activity.
To complete the injection, the debugger must perform the following steps: | trusted_official_docs | CPython Docs | the interpreter during execution. Setting bit 5 (``_PY_EVAL_PLEASE_STOP_BIT``, value ``1U << 5``) in this field causes the interpreter to pause and check for debugger activity.
To complete the injection, the debugger must perform the following steps: | the interpreter during execution. Setting bit 5 (``_PY_EVAL_PLEASE_STOP_BIT``, value ``1U << 5``) in this field causes the interpreter to pause and check for debugger activity.
To complete the injection, the debugger must perform the following steps: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9c37678e-cf05-40c6-bcf9-8f52d797d01c | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,746 | supabase-export-v2 | 02ab2b09ac1167b2 | Locating the interpreter and thread state =========================================
Before code can be injected and executed in a remote Python process, the
debugger must choose a thread in which to schedule execution. This is necessary
because the control fields used to perform remote code injection are located in
the... | trusted_official_docs | CPython Docs | Locating the interpreter and thread state =========================================
Before code can be injected and executed in a remote Python process, the
debugger must choose a thread in which to schedule execution. This is necessary
because the control fields used to perform remote code injection are located in
the... | Locating the interpreter and thread state =========================================
Before code can be injected and executed in a remote Python process, the
debugger must choose a thread in which to schedule execution. This is necessary
because the control fields used to perform remote code injection are located in
the... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9e0d8a1b-affa-4256-a7a3-f45dac12d28c | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,723 | supabase-export-v2 | bcfbc644ee59b9ac | PyRuntime # section. The section name appears as "PyRuntim" due to the # 8-character limit defined by the PE format (IMAGE_SIZEOF_SHORT_NAME). section_rva = parse_pe_section_offset(binary_path, "PyRuntim")
# Step 4: Compute PyRuntime address in memory
return base_address + section_rva | trusted_official_docs | CPython Docs | PyRuntime # section. The section name appears as "PyRuntim" due to the # 8-character limit defined by the PE format (IMAGE_SIZEOF_SHORT_NAME). section_rva = parse_pe_section_offset(binary_path, "PyRuntim")
# Step 4: Compute PyRuntime address in memory
return base_address + section_rva | PyRuntime # section. The section name appears as "PyRuntim" due to the # 8-character limit defined by the PE format (IMAGE_SIZEOF_SHORT_NAME). section_rva = parse_pe_section_offset(binary_path, "PyRuntim")
# Step 4: Compute PyRuntime address in memory
return base_address + section_rva | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9e39826c-cf2a-43da-af6a-50545f2df26e | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,779 | supabase-export-v2 | 6f28e264cd1c2fcc | 1 << 5) in # eval_breaker eval_breaker_ptr = ( thread_state_addr + debug_offsets.debugger_support.eval_breaker ) breaker = read_int(pid, eval_breaker_ptr) breaker |= (1 << 5) write_int(pid, eval_breaker_ptr, breaker)
Once these fields are set, the debugger may resume the process (if it was
suspended). The interpreter w... | trusted_official_docs | CPython Docs | 1 << 5) in # eval_breaker eval_breaker_ptr = ( thread_state_addr + debug_offsets.debugger_support.eval_breaker ) breaker = read_int(pid, eval_breaker_ptr) breaker |= (1 << 5) write_int(pid, eval_breaker_ptr, breaker)
Once these fields are set, the debugger may resume the process (if it was
suspended). The interpreter w... | 1 << 5) in # eval_breaker eval_breaker_ptr = ( thread_state_addr + debug_offsets.debugger_support.eval_breaker ) breaker = read_int(pid, eval_breaker_ptr) breaker |= (1 << 5) write_int(pid, eval_breaker_ptr, breaker)
Once these fields are set, the debugger may resume the process (if it was
suspended). The interpreter w... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9eb7cffa-1a1e-43f7-9bfc-4b771cff90d3 | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,709 | supabase-export-v2 | 5782c2aea9330a30 | # Step 3: Fallback to libpython if the executable is not found if binary_path is None: binary_path, base_address = find_mapped_binary( handle, name_contains="libpython" )
# Step 4: Parse Mach-O headers to get __DATA,__PyRuntime section offset
section_offset = parse_macho_section_offset(
binary_path, "__DATA", "__PyRu... | trusted_official_docs | CPython Docs | # Step 3: Fallback to libpython if the executable is not found if binary_path is None: binary_path, base_address = find_mapped_binary( handle, name_contains="libpython" )
# Step 4: Parse Mach-O headers to get __DATA,__PyRuntime section offset
section_offset = parse_macho_section_offset(
binary_path, "__DATA", "__PyRu... | # Step 3: Fallback to libpython if the executable is not found if binary_path is None: binary_path, base_address = find_mapped_binary( handle, name_contains="libpython" )
# Step 4: Parse Mach-O headers to get __DATA,__PyRuntime section offset
section_offset = parse_macho_section_offset(
binary_path, "__DATA", "__PyRu... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9f89803f-8b06-42f9-8663-bd4bf6b68703 | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,748 | supabase-export-v2 | 17b8c54dc4c54cae | the thread’s evaluation context and contains the fields required for debugger coordination. Locating a valid ``PyThreadState`` is therefore a key prerequisite for triggering execution remotely.
A thread is typically selected based on its role or ID. In most cases, the main
thread is used, but some tools may target a sp... | trusted_official_docs | CPython Docs | the thread’s evaluation context and contains the fields required for debugger coordination. Locating a valid ``PyThreadState`` is therefore a key prerequisite for triggering execution remotely.
A thread is typically selected based on its role or ID. In most cases, the main
thread is used, but some tools may target a sp... | the thread’s evaluation context and contains the fields required for debugger coordination. Locating a valid ``PyThreadState`` is therefore a key prerequisite for triggering execution remotely.
A thread is typically selected based on its role or ID. In most cases, the main
thread is used, but some tools may target a sp... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a0f77825-9843-4d68-bd83-784d1db87655 | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,793 | supabase-export-v2 | 477d9fefe82909d2 | the attacker already controls execution in that process. Demonstrating further impact from that starting point does not constitute a vulnerability in the remote debugging protocol.
When to use ``PYTHON_DISABLE_REMOTE_DEBUG``
------------------------------------------- | trusted_official_docs | CPython Docs | the attacker already controls execution in that process. Demonstrating further impact from that starting point does not constitute a vulnerability in the remote debugging protocol.
When to use ``PYTHON_DISABLE_REMOTE_DEBUG``
------------------------------------------- | the attacker already controls execution in that process. Demonstrating further impact from that starting point does not constitute a vulnerability in the remote debugging protocol.
When to use ``PYTHON_DISABLE_REMOTE_DEBUG``
------------------------------------------- | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a2e326d3-0363-4170-a179-c43c02976953 | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,736 | supabase-export-v2 | 905b22cbd7fdb8c4 | be used to locate fields in memory. If any check fails, the debugger should stop the operation to avoid reading memory in the wrong format.
The following is an example implementation that reads and checks
``_Py_DebugOffsets``:: | trusted_official_docs | CPython Docs | be used to locate fields in memory. If any check fails, the debugger should stop the operation to avoid reading memory in the wrong format.
The following is an example implementation that reads and checks
``_Py_DebugOffsets``:: | be used to locate fields in memory. If any check fails, the debugger should stop the operation to avoid reading memory in the wrong format.
The following is an example implementation that reads and checks
``_Py_DebugOffsets``:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a4119020-1e39-4424-b8f4-b7ca3e5aca63 | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,777 | supabase-export-v2 | e00c5553f8aa8854 | # Step 1: Write the script path into debugger_script_path script_path_ptr = ( support_base + debug_offsets.debugger_support.debugger_script_path ) write_string(pid, script_path_ptr, script_path)
# Step 2: Set debugger_pending_call to 1
pending_ptr = (
support_base +
debug_offsets.debugger_support.debugger_pending_ca... | trusted_official_docs | CPython Docs | # Step 1: Write the script path into debugger_script_path script_path_ptr = ( support_base + debug_offsets.debugger_support.debugger_script_path ) write_string(pid, script_path_ptr, script_path)
# Step 2: Set debugger_pending_call to 1
pending_ptr = (
support_base +
debug_offsets.debugger_support.debugger_pending_ca... | # Step 1: Write the script path into debugger_script_path script_path_ptr = ( support_base + debug_offsets.debugger_support.debugger_script_path ) write_string(pid, script_path_ptr, script_path)
# Step 2: Set debugger_pending_call to 1
pending_ptr = (
support_base +
debug_offsets.debugger_support.debugger_pending_ca... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
aa256684-17ce-4f6e-ae56-c09f16cab28d | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,734 | supabase-export-v2 | 370ae588235c7aee | 2. Check that the structure contains valid data:
- The ``cookie`` field must match the expected debug marker. - The ``version`` field must match the version of the Python interpreter
used by the debugger. - If either the debugger or the target process is using a pre-release
version (for example, an alpha, beta, or re... | trusted_official_docs | CPython Docs | 2. Check that the structure contains valid data:
- The ``cookie`` field must match the expected debug marker. - The ``version`` field must match the version of the Python interpreter
used by the debugger. - If either the debugger or the target process is using a pre-release
version (for example, an alpha, beta, or re... | 2. Check that the structure contains valid data:
- The ``cookie`` field must match the expected debug marker. - The ``version`` field must match the version of the Python interpreter
used by the debugger. - If either the debugger or the target process is using a pre-release
version (for example, an alpha, beta, or re... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
acf67c73-4394-4237-8cbc-e17242cddd70 | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,699 | supabase-export-v2 | c0645e361e496874 | # Step 4: Compute PyRuntime address in memory return base_address + section_offset
On Linux systems, there are two main approaches to read memory from another
process. The first is through the ``/proc`` filesystem, specifically by reading from
``/proc/[pid]/mem`` which provides direct access to the process's memory. Th... | trusted_official_docs | CPython Docs | # Step 4: Compute PyRuntime address in memory return base_address + section_offset
On Linux systems, there are two main approaches to read memory from another
process. The first is through the ``/proc`` filesystem, specifically by reading from
``/proc/[pid]/mem`` which provides direct access to the process's memory. Th... | # Step 4: Compute PyRuntime address in memory return base_address + section_offset
On Linux systems, there are two main approaches to read memory from another
process. The first is through the ``/proc`` filesystem, specifically by reading from
``/proc/[pid]/mem`` which provides direct access to the process's memory. Th... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b29adc1a-903e-4fdc-adee-4797774ed2c8 | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,682 | supabase-export-v2 | fee82a79cce770ac | depends on the interpreter reaching a safe evaluation point. As a result, execution may be delayed depending on the runtime state of the target process.
Once injected, the script is executed by the interpreter within the target
process the next time a safe evaluation point is reached. This approach enables
remote execu... | trusted_official_docs | CPython Docs | depends on the interpreter reaching a safe evaluation point. As a result, execution may be delayed depending on the runtime state of the target process.
Once injected, the script is executed by the interpreter within the target
process the next time a safe evaluation point is reached. This approach enables
remote execu... | depends on the interpreter reaching a safe evaluation point. As a result, execution may be delayed depending on the runtime state of the target process.
Once injected, the script is executed by the interpreter within the target
process the next time a safe evaluation point is reached. This approach enables
remote execu... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b38f67d1-bfcc-45ce-a803-a62654b071c0 | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,689 | supabase-export-v2 | 59e30fd2f64ff21b | The method for finding ``PyRuntime`` depends on the platform, but the steps are the same in general:
1. Find the base address where the Python binary or shared library was loaded
in the target process. 2. Use the on-disk binary to locate the offset of the ``.PyRuntime`` section. 3. Add the section offset to the base a... | trusted_official_docs | CPython Docs | The method for finding ``PyRuntime`` depends on the platform, but the steps are the same in general:
1. Find the base address where the Python binary or shared library was loaded
in the target process. 2. Use the on-disk binary to locate the offset of the ``.PyRuntime`` section. 3. Add the section offset to the base a... | The method for finding ``PyRuntime`` depends on the platform, but the steps are the same in general:
1. Find the base address where the Python binary or shared library was loaded
in the target process. 2. Use the on-disk binary to locate the offset of the ``.PyRuntime`` section. 3. Add the section offset to the base a... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b65850f1-6f3d-4c0f-a6b0-31b055d5b83c | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,731 | supabase-export-v2 | 2b30a131251015b8 | to safely read interpreter and thread state memory. These offsets vary between CPython versions and must be checked before use to ensure they are compatible.
To read and check the debug offsets, follow these steps: | trusted_official_docs | CPython Docs | to safely read interpreter and thread state memory. These offsets vary between CPython versions and must be checked before use to ensure they are compatible.
To read and check the debug offsets, follow these steps: | to safely read interpreter and thread state memory. These offsets vary between CPython versions and must be checked before use to ensure they are compatible.
To read and check the debug offsets, follow these steps: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c0853eb1-bb76-4718-8cf6-ac07c9ce9f2f | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,675 | supabase-export-v2 | b160c8ba2b9f0069 | To resolve file or folder access issues, adjust the security permissions:
1. Right-click the file or folder and select **Properties**. 2. Go to the **Security** tab to view users and groups with access. 3. Click **Edit** to modify permissions. 4. Select your user account. 5. In **Permissions**, check **Read** or **Full... | trusted_official_docs | CPython Docs | To resolve file or folder access issues, adjust the security permissions:
1. Right-click the file or folder and select **Properties**. 2. Go to the **Security** tab to view users and groups with access. 3. Click **Edit** to modify permissions. 4. Select your user account. 5. In **Permissions**, check **Read** or **Full... | To resolve file or folder access issues, adjust the security permissions:
1. Right-click the file or folder and select **Properties**. 2. Go to the **Security** tab to view users and groups with access. 3. Click **Edit** to modify permissions. 4. Select your user account. 5. In **Permissions**, check **Read** or **Full... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c243180a-84d3-4fb1-9046-6a8266ed6641 | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,790 | supabase-export-v2 | 6782486971cedc76 | The following principles define what is, and is not, considered a security vulnerability in this feature:
Attaching requires OS-level privileges
On every supported platform the operating system gates cross-process
memory access behind privilege checks (``CAP_SYS_PTRACE``, root, or
administrator rights). A report tha... | trusted_official_docs | CPython Docs | The following principles define what is, and is not, considered a security vulnerability in this feature:
Attaching requires OS-level privileges
On every supported platform the operating system gates cross-process
memory access behind privilege checks (``CAP_SYS_PTRACE``, root, or
administrator rights). A report tha... | The following principles define what is, and is not, considered a security vulnerability in this feature:
Attaching requires OS-level privileges
On every supported platform the operating system gates cross-process
memory access behind privilege checks (``CAP_SYS_PTRACE``, root, or
administrator rights). A report tha... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c412ea9e-1c9a-40ed-9731-fbc02109b376 | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,737 | supabase-export-v2 | 8c5dd356e07c977a | The following is an example implementation that reads and checks ``_Py_DebugOffsets``::
def read_debug_offsets(pid: int, py_runtime_addr: int) -> DebugOffsets:
# Step 1: Read memory from the target process at the PyRuntime address
data = read_process_memory(
pid, address=py_runtime_addr, size=DEBUG_OFFSETS_SIZE
) | trusted_official_docs | CPython Docs | The following is an example implementation that reads and checks ``_Py_DebugOffsets``::
def read_debug_offsets(pid: int, py_runtime_addr: int) -> DebugOffsets:
# Step 1: Read memory from the target process at the PyRuntime address
data = read_process_memory(
pid, address=py_runtime_addr, size=DEBUG_OFFSETS_SIZE
) | The following is an example implementation that reads and checks ``_Py_DebugOffsets``::
def read_debug_offsets(pid: int, py_runtime_addr: int) -> DebugOffsets:
# Step 1: Read memory from the target process at the PyRuntime address
data = read_process_memory(
pid, address=py_runtime_addr, size=DEBUG_OFFSETS_SIZE
) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c9f80680-d04c-454b-8213-692ed55fe12e | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,751 | supabase-export-v2 | 3a5098cfcd823708 | of imported modules, built-in state, and thread state list. Although most Python applications use a single interpreter, CPython supports multiple interpreters in the same process.
- ``PyThreadState`` represents a thread running within an interpreter. It
contains execution state and the control fields used by the debug... | trusted_official_docs | CPython Docs | of imported modules, built-in state, and thread state list. Although most Python applications use a single interpreter, CPython supports multiple interpreters in the same process.
- ``PyThreadState`` represents a thread running within an interpreter. It
contains execution state and the control fields used by the debug... | of imported modules, built-in state, and thread state list. Although most Python applications use a single interpreter, CPython supports multiple interpreters in the same process.
- ``PyThreadState`` represents a thread running within an interpreter. It
contains execution state and the control fields used by the debug... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ca661511-7c7c-4de7-9d56-190fbcb96032 | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,791 | supabase-export-v2 | 54d9f35ebcba297f | demonstrates an issue only after these privileges have already been obtained is **not** a vulnerability in CPython, since the OS security boundary was already crossed.
Crashes or memory errors when reading a compromised process are not vulnerabilities
A tool that reads internal interpreter state from a target process ... | trusted_official_docs | CPython Docs | demonstrates an issue only after these privileges have already been obtained is **not** a vulnerability in CPython, since the OS security boundary was already crossed.
Crashes or memory errors when reading a compromised process are not vulnerabilities
A tool that reads internal interpreter state from a target process ... | demonstrates an issue only after these privileges have already been obtained is **not** a vulnerability in CPython, since the OS security boundary was already crossed.
Crashes or memory errors when reading a compromised process are not vulnerabilities
A tool that reads internal interpreter state from a target process ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
cb049802-52a8-466c-a409-0f1029c8c1f3 | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,727 | supabase-export-v2 | 10f77c1e24fc8484 | section in the PE headers. The final address is computed by combining the base address with the section's virtual address from the PE section headers.
Note that accessing another process's memory on Windows typically requires
appropriate privileges - either administrative access or the ``SeDebugPrivilege``
privilege gr... | trusted_official_docs | CPython Docs | section in the PE headers. The final address is computed by combining the base address with the section's virtual address from the PE section headers.
Note that accessing another process's memory on Windows typically requires
appropriate privileges - either administrative access or the ``SeDebugPrivilege``
privilege gr... | section in the PE headers. The final address is computed by combining the base address with the section's virtual address from the PE section headers.
Note that accessing another process's memory on Windows typically requires
appropriate privileges - either administrative access or the ``SeDebugPrivilege``
privilege gr... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
cb5c57bc-a084-4b60-b591-018011996958 | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,721 | supabase-export-v2 | 43261372826103e2 | def find_py_runtime_windows(pid: int) -> int: # Step 1: Try to find the Python executable in memory binary_path, base_address = find_loaded_module( pid, name_contains="python" )
# Step 2: Fallback to shared pythonXY.dll if the executable is not
# found
if binary_path is None:
binary_path, base_address = find_loaded_... | trusted_official_docs | CPython Docs | def find_py_runtime_windows(pid: int) -> int: # Step 1: Try to find the Python executable in memory binary_path, base_address = find_loaded_module( pid, name_contains="python" )
# Step 2: Fallback to shared pythonXY.dll if the executable is not
# found
if binary_path is None:
binary_path, base_address = find_loaded_... | def find_py_runtime_windows(pid: int) -> int: # Step 1: Try to find the Python executable in memory binary_path, base_address = find_loaded_module( pid, name_contains="python" )
# Step 2: Fallback to shared pythonXY.dll if the executable is not
# found
if binary_path is None:
binary_path, base_address = find_loaded_... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
cb8685f7-9857-4ff2-ab80-ada5f76f4f1a | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,708 | supabase-export-v2 | 3ce67efbd13a012b | # Step 2: Try to find the Python executable in memory binary_path, base_address = find_mapped_binary( handle, name_contains="python" )
# Step 3: Fallback to libpython if the executable is not found
if binary_path is None:
binary_path, base_address = find_mapped_binary(
handle, name_contains="libpython"
) | trusted_official_docs | CPython Docs | # Step 2: Try to find the Python executable in memory binary_path, base_address = find_mapped_binary( handle, name_contains="python" )
# Step 3: Fallback to libpython if the executable is not found
if binary_path is None:
binary_path, base_address = find_mapped_binary(
handle, name_contains="libpython"
) | # Step 2: Try to find the Python executable in memory binary_path, base_address = find_mapped_binary( handle, name_contains="python" )
# Step 3: Fallback to libpython if the executable is not found
if binary_path is None:
binary_path, base_address = find_mapped_binary(
handle, name_contains="libpython"
) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
cf4d8c6a-df49-46a0-a63d-a323d430e571 | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,713 | supabase-export-v2 | cb7bf54737b06945 | loaded at each memory region. When the Python binary or library is found, its Mach-O headers need to be parsed to locate the ``PyRuntime`` structure.
The Mach-O format organizes code and data into segments and sections. The
``PyRuntime`` structure lives in a section named ``__PyRuntime`` within the
``__DATA`` segment. ... | trusted_official_docs | CPython Docs | loaded at each memory region. When the Python binary or library is found, its Mach-O headers need to be parsed to locate the ``PyRuntime`` structure.
The Mach-O format organizes code and data into segments and sections. The
``PyRuntime`` structure lives in a section named ``__PyRuntime`` within the
``__DATA`` segment. ... | loaded at each memory region. When the Python binary or library is found, its Mach-O headers need to be parsed to locate the ``PyRuntime`` structure.
The Mach-O format organizes code and data into segments and sections. The
``PyRuntime`` structure lives in a section named ``__PyRuntime`` within the
``__DATA`` segment. ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d17f3ffa-af3c-4ca9-bd0c-8e2e78467851 | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,687 | supabase-export-v2 | bd27ecfbef48548e | ``PyRuntime`` structure contains CPython’s global interpreter state and provides access to other internal data, including the list of interpreters, thread states, and debugger support fields.
To work with a remote Python process, a debugger must first find the memory
address of the ``PyRuntime`` structure in the target... | trusted_official_docs | CPython Docs | ``PyRuntime`` structure contains CPython’s global interpreter state and provides access to other internal data, including the list of interpreters, thread states, and debugger support fields.
To work with a remote Python process, a debugger must first find the memory
address of the ``PyRuntime`` structure in the target... | ``PyRuntime`` structure contains CPython’s global interpreter state and provides access to other internal data, including the list of interpreters, thread states, and debugger support fields.
To work with a remote Python process, a debugger must first find the memory
address of the ``PyRuntime`` structure in the target... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d203e0fb-d6cc-4870-ba47-2262f5e603ef | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,684 | supabase-export-v2 | 0df21a7bdd76bc99 | in memory, safely accessing internal fields, and triggering code execution. Platform-specific variations are noted where applicable, and example implementations are included to clarify each operation.
Locating the PyRuntime structure
================================ | trusted_official_docs | CPython Docs | in memory, safely accessing internal fields, and triggering code execution. Platform-specific variations are noted where applicable, and example implementations are included to clarify each operation.
Locating the PyRuntime structure
================================ | in memory, safely accessing internal fields, and triggering code execution. Platform-specific variations are noted where applicable, and example implementations are included to clarify each operation.
Locating the PyRuntime structure
================================ | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d225714f-0e2b-449d-82c3-d0443879213d | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,792 | supabase-export-v2 | 29591e0ecbe7cb4e | (buffer overflows, segmentation faults, or undefined behaviour triggered by reading corrupted state) are **not** treated as security issues, though fixes that improve robustness are welcome.
Vulnerabilities in the target process are not in scope
If the Python process being debugged has already been compromised, the
a... | trusted_official_docs | CPython Docs | (buffer overflows, segmentation faults, or undefined behaviour triggered by reading corrupted state) are **not** treated as security issues, though fixes that improve robustness are welcome.
Vulnerabilities in the target process are not in scope
If the Python process being debugged has already been compromised, the
a... | (buffer overflows, segmentation faults, or undefined behaviour triggered by reading corrupted state) are **not** treated as security issues, though fixes that improve robustness are welcome.
Vulnerabilities in the target process are not in scope
If the Python process being debugged has already been compromised, the
a... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d5a28d34-a374-4af2-a210-d285387f1e98 | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,718 | supabase-export-v2 | 4f5f31aaa015bd29 | address. 3. Locate the ``PyRuntim`` section. Due to the PE format's 8-character limit on section names (defined as ``IMAGE_SIZEOF_SHORT_NAME``), the original name ``PyRuntime`` is truncated.
This section contains the ``PyRuntime``
structure. 4. Retrieve the section’s relative virtual address (RVA) and add it to the ba... | trusted_official_docs | CPython Docs | address. 3. Locate the ``PyRuntim`` section. Due to the PE format's 8-character limit on section names (defined as ``IMAGE_SIZEOF_SHORT_NAME``), the original name ``PyRuntime`` is truncated.
This section contains the ``PyRuntime``
structure. 4. Retrieve the section’s relative virtual address (RVA) and add it to the ba... | address. 3. Locate the ``PyRuntim`` section. Due to the PE format's 8-character limit on section names (defined as ``IMAGE_SIZEOF_SHORT_NAME``), the original name ``PyRuntime`` is truncated.
This section contains the ``PyRuntime``
structure. 4. Retrieve the section’s relative virtual address (RVA) and add it to the ba... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d6b50394-1c16-4aeb-bd9b-2e9e72af4c9c | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,750 | supabase-export-v2 | 26417b49f83cb3c9 | The relevant internal structures are defined as follows:
- ``PyInterpreterState`` represents an isolated Python interpreter instance. Each interpreter maintains its own set of imported modules, built-in state,
and thread state list. Although most Python applications use a single
interpreter, CPython supports multiple... | trusted_official_docs | CPython Docs | The relevant internal structures are defined as follows:
- ``PyInterpreterState`` represents an isolated Python interpreter instance. Each interpreter maintains its own set of imported modules, built-in state,
and thread state list. Although most Python applications use a single
interpreter, CPython supports multiple... | The relevant internal structures are defined as follows:
- ``PyInterpreterState`` represents an isolated Python interpreter instance. Each interpreter maintains its own set of imported modules, built-in state,
and thread state list. Although most Python applications use a single
interpreter, CPython supports multiple... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d93c8193-1db6-46eb-9b4f-b9342ebf5b50 | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,738 | supabase-export-v2 | 161bf3f8c3ab7087 | int, py_runtime_addr: int) -> DebugOffsets: # Step 1: Read memory from the target process at the PyRuntime address data = read_process_memory( pid, address=py_runtime_addr, size=DEBUG_OFFSETS_SIZE )
# Step 2: Deserialize the raw bytes into a _Py_DebugOffsets structure
debug_offsets = parse_debug_offsets(data) | trusted_official_docs | CPython Docs | int, py_runtime_addr: int) -> DebugOffsets: # Step 1: Read memory from the target process at the PyRuntime address data = read_process_memory( pid, address=py_runtime_addr, size=DEBUG_OFFSETS_SIZE )
# Step 2: Deserialize the raw bytes into a _Py_DebugOffsets structure
debug_offsets = parse_debug_offsets(data) | int, py_runtime_addr: int) -> DebugOffsets: # Step 1: Read memory from the target process at the PyRuntime address data = read_process_memory( pid, address=py_runtime_addr, size=DEBUG_OFFSETS_SIZE )
# Step 2: Deserialize the raw bytes into a _Py_DebugOffsets structure
debug_offsets = parse_debug_offsets(data) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
e34504b1-671f-41d3-aac2-8cc9a4542b6e | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,739 | supabase-export-v2 | 9d1c48653c5d8a53 | # Step 2: Deserialize the raw bytes into a _Py_DebugOffsets structure debug_offsets = parse_debug_offsets(data)
# Step 3: Validate the contents of the structure
if debug_offsets.cookie != EXPECTED_COOKIE:
raise RuntimeError("Invalid or missing debug cookie")
if debug_offsets.version != LOCAL_PYTHON_VERSION:
raise R... | trusted_official_docs | CPython Docs | # Step 2: Deserialize the raw bytes into a _Py_DebugOffsets structure debug_offsets = parse_debug_offsets(data)
# Step 3: Validate the contents of the structure
if debug_offsets.cookie != EXPECTED_COOKIE:
raise RuntimeError("Invalid or missing debug cookie")
if debug_offsets.version != LOCAL_PYTHON_VERSION:
raise R... | # Step 2: Deserialize the raw bytes into a _Py_DebugOffsets structure debug_offsets = parse_debug_offsets(data)
# Step 3: Validate the contents of the structure
if debug_offsets.cookie != EXPECTED_COOKIE:
raise RuntimeError("Invalid or missing debug cookie")
if debug_offsets.version != LOCAL_PYTHON_VERSION:
raise R... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
e89eb829-0a3d-4397-8356-5273b3fbbc50 | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,794 | supabase-export-v2 | 42615ed24c869614 | When to use ``PYTHON_DISABLE_REMOTE_DEBUG`` -------------------------------------------
The environment variable :envvar:`PYTHON_DISABLE_REMOTE_DEBUG` (and the
equivalent :option:`-X disable_remote_debug` flag) allows operators to disable
the in-process side of the protocol as a **defence-in-depth** measure. This
may b... | trusted_official_docs | CPython Docs | When to use ``PYTHON_DISABLE_REMOTE_DEBUG`` -------------------------------------------
The environment variable :envvar:`PYTHON_DISABLE_REMOTE_DEBUG` (and the
equivalent :option:`-X disable_remote_debug` flag) allows operators to disable
the in-process side of the protocol as a **defence-in-depth** measure. This
may b... | When to use ``PYTHON_DISABLE_REMOTE_DEBUG`` -------------------------------------------
The environment variable :envvar:`PYTHON_DISABLE_REMOTE_DEBUG` (and the
equivalent :option:`-X disable_remote_debug` flag) allows operators to disable
the in-process side of the protocol as a **defence-in-depth** measure. This
may b... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ea86932a-9cf4-4aca-8720-07e07b99e239 | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,776 | supabase-export-v2 | cc00d550a903bacf | pid: int, thread_state_addr: int, debug_offsets: DebugOffsets, script_path: str ) -> None: # Compute the base offset of _PyRemoteDebuggerSupport support_base = ( thread_state_addr + debug_offsets.debugger_support.remote_debugger_support )
# Step 1: Write the script path into debugger_script_path
script_path_ptr = (
s... | trusted_official_docs | CPython Docs | pid: int, thread_state_addr: int, debug_offsets: DebugOffsets, script_path: str ) -> None: # Compute the base offset of _PyRemoteDebuggerSupport support_base = ( thread_state_addr + debug_offsets.debugger_support.remote_debugger_support )
# Step 1: Write the script path into debugger_script_path
script_path_ptr = (
s... | pid: int, thread_state_addr: int, debug_offsets: DebugOffsets, script_path: str ) -> None: # Compute the base offset of _PyRemoteDebuggerSupport support_base = ( thread_state_addr + debug_offsets.debugger_support.remote_debugger_support )
# Step 1: Write the script path into debugger_script_path
script_path_ptr = (
s... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ebbd1cb4-37be-4edc-9178-2bfef6160661 | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,788 | supabase-export-v2 | 9e78bd0d933db943 | Security and threat model =========================
The remote debugging protocol relies on the same operating system primitives
used by native debuggers such as GDB and LLDB. Attaching to a process
requires the **same privileges** that those debuggers require, for example
``ptrace`` / Yama LSM on Linux, ``task_for_pid... | trusted_official_docs | CPython Docs | Security and threat model =========================
The remote debugging protocol relies on the same operating system primitives
used by native debuggers such as GDB and LLDB. Attaching to a process
requires the **same privileges** that those debuggers require, for example
``ptrace`` / Yama LSM on Linux, ``task_for_pid... | Security and threat model =========================
The remote debugging protocol relies on the same operating system primitives
used by native debuggers such as GDB and LLDB. Attaching to a process
requires the **same privileges** that those debuggers require, for example
``ptrace`` / Yama LSM on Linux, ``task_for_pid... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ee9b5911-296f-49c1-b461-56818724e0be | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,707 | supabase-export-v2 | 18031141727dc204 | def find_py_runtime_macos(pid: int) -> int: # Step 1: Get access to the process's memory handle = get_memory_access_handle(pid)
# Step 2: Try to find the Python executable in memory
binary_path, base_address = find_mapped_binary(
handle, name_contains="python"
) | trusted_official_docs | CPython Docs | def find_py_runtime_macos(pid: int) -> int: # Step 1: Get access to the process's memory handle = get_memory_access_handle(pid)
# Step 2: Try to find the Python executable in memory
binary_path, base_address = find_mapped_binary(
handle, name_contains="python"
) | def find_py_runtime_macos(pid: int) -> int: # Step 1: Get access to the process's memory handle = get_memory_access_handle(pid)
# Step 2: Try to find the Python executable in memory
binary_path, base_address = find_mapped_binary(
handle, name_contains="python"
) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ef41b565-9004-4785-ba71-bae64bd56df6 | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,735 | supabase-export-v2 | bfb2140aea44b06c | or release candidate), the versions must match exactly. - The ``free_threaded`` field must have the same value in both the debugger and the target process.
3. If the structure is valid, the offsets it contains can be used to locate
fields in memory. If any check fails, the debugger should stop the operation
to avoid ... | trusted_official_docs | CPython Docs | or release candidate), the versions must match exactly. - The ``free_threaded`` field must have the same value in both the debugger and the target process.
3. If the structure is valid, the offsets it contains can be used to locate
fields in memory. If any check fails, the debugger should stop the operation
to avoid ... | or release candidate), the versions must match exactly. - The ``free_threaded`` field must have the same value in both the debugger and the target process.
3. If the structure is valid, the offsets it contains can be used to locate
fields in memory. If any check fails, the debugger should stop the operation
to avoid ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ef6758e8-1918-49d5-896a-b44e8f08a9dc | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,754 | supabase-export-v2 | 9c6e75bb9bd383fe | ``runtime_state.interpreters_head`` to obtain the address of the first interpreter in the ``PyRuntime`` structure. This is the entry point to the linked list of active interpreters.
2. Use the offset ``interpreter_state.threads_main`` to access the main thread
state associated with the selected interpreter. This is ty... | trusted_official_docs | CPython Docs | ``runtime_state.interpreters_head`` to obtain the address of the first interpreter in the ``PyRuntime`` structure. This is the entry point to the linked list of active interpreters.
2. Use the offset ``interpreter_state.threads_main`` to access the main thread
state associated with the selected interpreter. This is ty... | ``runtime_state.interpreters_head`` to obtain the address of the first interpreter in the ``PyRuntime`` structure. This is the entry point to the linked list of active interpreters.
2. Use the offset ``interpreter_state.threads_main`` to access the main thread
state associated with the selected interpreter. This is ty... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ef8903a0-6b1c-4ae7-95d8-0145ee97699a | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,742 | supabase-export-v2 | c52ef1711df6e9b3 | The Python runtime may concurrently mutate interpreter data structures—such as creating or destroying threads—during normal execution. This can result in invalid memory reads or writes.
A debugger may suspend execution by attaching to the process with ``ptrace``
or by sending a ``SIGSTOP`` signal. Execution should onl... | trusted_official_docs | CPython Docs | The Python runtime may concurrently mutate interpreter data structures—such as creating or destroying threads—during normal execution. This can result in invalid memory reads or writes.
A debugger may suspend execution by attaching to the process with ``ptrace``
or by sending a ``SIGSTOP`` signal. Execution should onl... | The Python runtime may concurrently mutate interpreter data structures—such as creating or destroying threads—during normal execution. This can result in invalid memory reads or writes.
A debugger may suspend execution by attaching to the process with ``ptrace``
or by sending a ``SIGSTOP`` signal. Execution should onl... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f18da90f-b25e-439d-9b90-662c8762d9d3 | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,711 | supabase-export-v2 | 535b82d4ef075106 | # Step 5: Compute the PyRuntime address in memory return base_address + section_offset
On macOS, accessing another process's memory requires using Mach-O specific APIs
and file formats. The first step is obtaining a ``task_port`` handle via
``task_for_pid()``, which provides access to the target process's memory space.... | trusted_official_docs | CPython Docs | # Step 5: Compute the PyRuntime address in memory return base_address + section_offset
On macOS, accessing another process's memory requires using Mach-O specific APIs
and file formats. The first step is obtaining a ``task_port`` handle via
``task_for_pid()``, which provides access to the target process's memory space.... | # Step 5: Compute the PyRuntime address in memory return base_address + section_offset
On macOS, accessing another process's memory requires using Mach-O specific APIs
and file formats. The first step is obtaining a ``task_port`` handle via
``task_for_pid()``, which provides access to the target process's memory space.... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f1d3e734-abc8-4301-a5bb-b1133b4254c4 | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,730 | supabase-export-v2 | eca6d188320e8bca | address of the ``PyRuntime`` structure has been determined, the next step is to read the ``_Py_DebugOffsets`` structure located at the beginning of the ``PyRuntime`` block.
This structure provides version-specific field offsets that are needed to
safely read interpreter and thread state memory. These offsets vary betwe... | trusted_official_docs | CPython Docs | address of the ``PyRuntime`` structure has been determined, the next step is to read the ``_Py_DebugOffsets`` structure located at the beginning of the ``PyRuntime`` block.
This structure provides version-specific field offsets that are needed to
safely read interpreter and thread state memory. These offsets vary betwe... | address of the ``PyRuntime`` structure has been determined, the next step is to read the ``_Py_DebugOffsets`` structure located at the beginning of the ``PyRuntime`` block.
This structure provides version-specific field offsets that are needed to
safely read interpreter and thread state memory. These offsets vary betwe... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f212b37c-3a5a-4834-9e43-451d636972cb | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,732 | supabase-export-v2 | 61efab1901bf8988 | To read and check the debug offsets, follow these steps:
1. Read memory from the target process starting at the ``PyRuntime`` address,
covering the same number of bytes as the ``_Py_DebugOffsets`` structure. This structure is located at the very start of the ``PyRuntime`` memory
block. Its layout is defined in CPytho... | trusted_official_docs | CPython Docs | To read and check the debug offsets, follow these steps:
1. Read memory from the target process starting at the ``PyRuntime`` address,
covering the same number of bytes as the ``_Py_DebugOffsets`` structure. This structure is located at the very start of the ``PyRuntime`` memory
block. Its layout is defined in CPytho... | To read and check the debug offsets, follow these steps:
1. Read memory from the target process starting at the ``PyRuntime`` address,
covering the same number of bytes as the ``_Py_DebugOffsets`` structure. This structure is located at the very start of the ``PyRuntime`` memory
block. Its layout is defined in CPytho... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f3a3193d-d9cc-45da-b823-a9b765f01ca0 | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,789 | supabase-export-v2 | ebb6c72485252079 | path; if an attacker already possesses the permissions needed to attach to a process, they could equally use GDB to read memory or inject code.
The following principles define what is, and is not, considered a security
vulnerability in this feature: | trusted_official_docs | CPython Docs | path; if an attacker already possesses the permissions needed to attach to a process, they could equally use GDB to read memory or inject code.
The following principles define what is, and is not, considered a security
vulnerability in this feature: | path; if an attacker already possesses the permissions needed to attach to a process, they could equally use GDB to read memory or inject code.
The following principles define what is, and is not, considered a security
vulnerability in this feature: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f88ea120-23ff-445d-ab5f-51254af1cede | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,679 | supabase-export-v2 | 4d4ca8bb50438d92 | This section describes the low-level protocol that enables external tools to inject and execute a Python script within a running CPython process.
This mechanism forms the basis of the :func:`sys.remote_exec` function, which
instructs a remote Python process to execute a ``.py`` file. However, this
section does not docu... | trusted_official_docs | CPython Docs | This section describes the low-level protocol that enables external tools to inject and execute a Python script within a running CPython process.
This mechanism forms the basis of the :func:`sys.remote_exec` function, which
instructs a remote Python process to execute a ``.py`` file. However, this
section does not docu... | This section describes the low-level protocol that enables external tools to inject and execute a Python script within a running CPython process.
This mechanism forms the basis of the :func:`sys.remote_exec` function, which
instructs a remote Python process to execute a ``.py`` file. However, this
section does not docu... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
fbdf6bd2-9bdb-4114-880c-3d634b5f93db | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,696 | supabase-export-v2 | 100a8b5c69a53db1 | def find_py_runtime_linux(pid: int) -> int: # Step 1: Try to find the Python executable in memory binary_path, base_address = find_mapped_binary( pid, name_contains="python" )
# Step 2: Fallback to shared library if executable is not found
if binary_path is None:
binary_path, base_address = find_mapped_binary(
pid, ... | trusted_official_docs | CPython Docs | def find_py_runtime_linux(pid: int) -> int: # Step 1: Try to find the Python executable in memory binary_path, base_address = find_mapped_binary( pid, name_contains="python" )
# Step 2: Fallback to shared library if executable is not found
if binary_path is None:
binary_path, base_address = find_mapped_binary(
pid, ... | def find_py_runtime_linux(pid: int) -> int: # Step 1: Try to find the Python executable in memory binary_path, base_address = find_mapped_binary( pid, name_contains="python" )
# Step 2: Fallback to shared library if executable is not found
if binary_path is None:
binary_path, base_address = find_mapped_binary(
pid, ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
fc717794-1f30-4162-b2d8-7f329b7c0113 | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,778 | supabase-export-v2 | 47021ee52cec7a82 | # Step 2: Set debugger_pending_call to 1 pending_ptr = ( support_base + debug_offsets.debugger_support.debugger_pending_call ) write_int(pid, pending_ptr, 1)
# Step 3: Set _PY_EVAL_PLEASE_STOP_BIT (bit 5, value 1 << 5) in
# eval_breaker
eval_breaker_ptr = (
thread_state_addr +
debug_offsets.debugger_support.eval_br... | trusted_official_docs | CPython Docs | # Step 2: Set debugger_pending_call to 1 pending_ptr = ( support_base + debug_offsets.debugger_support.debugger_pending_call ) write_int(pid, pending_ptr, 1)
# Step 3: Set _PY_EVAL_PLEASE_STOP_BIT (bit 5, value 1 << 5) in
# eval_breaker
eval_breaker_ptr = (
thread_state_addr +
debug_offsets.debugger_support.eval_br... | # Step 2: Set debugger_pending_call to 1 pending_ptr = ( support_base + debug_offsets.debugger_support.debugger_pending_call ) write_int(pid, pending_ptr, 1)
# Step 3: Set _PY_EVAL_PLEASE_STOP_BIT (bit 5, value 1 << 5) in
# eval_breaker
eval_breaker_ptr = (
thread_state_addr +
debug_offsets.debugger_support.eval_br... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
fdf80ac7-2e92-4596-8d13-301c73053a12 | CPython Docs | file://datasets/cpython/Doc/howto/remote_debugging.rst | unknown | d9c2e866-dcc6-4f6c-8ad6-115777f459f9 | 57,759 | supabase-export-v2 | ee7c2b979eabb97c | from PyRuntime interp_head_ptr = ( py_runtime_addr + debug_offsets.runtime_state.interpreters_head ) interp_addr = read_pointer(pid, interp_head_ptr) if interp_addr == 0: raise RuntimeError("No interpreter found in the target process")
# Step 2: Read the threads_main pointer from the interpreter
threads_main_ptr = (
... | trusted_official_docs | CPython Docs | from PyRuntime interp_head_ptr = ( py_runtime_addr + debug_offsets.runtime_state.interpreters_head ) interp_addr = read_pointer(pid, interp_head_ptr) if interp_addr == 0: raise RuntimeError("No interpreter found in the target process")
# Step 2: Read the threads_main pointer from the interpreter
threads_main_ptr = (
... | from PyRuntime interp_head_ptr = ( py_runtime_addr + debug_offsets.runtime_state.interpreters_head ) interp_addr = read_pointer(pid, interp_head_ptr) if interp_addr == 0: raise RuntimeError("No interpreter found in the target process")
# Step 2: Read the threads_main pointer from the interpreter
threads_main_ptr = (
... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
02236f8a-71fa-4b5d-af28-a703ef4e7982 | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,817 | supabase-export-v2 | 6ae3efef7b16f575 | sys >>> import binascii >>> old_binascii = binascii >>> del sys.modules['binascii'] >>> import binascii # create a new module object >>> old_binascii == binascii False
As a rule of thumb, the two modules should be completely independent. All objects and state specific to the module should be encapsulated
within the mod... | trusted_official_docs | CPython Docs | sys >>> import binascii >>> old_binascii = binascii >>> del sys.modules['binascii'] >>> import binascii # create a new module object >>> old_binascii == binascii False
As a rule of thumb, the two modules should be completely independent. All objects and state specific to the module should be encapsulated
within the mod... | sys >>> import binascii >>> old_binascii = binascii >>> del sys.modules['binascii'] >>> import binascii # create a new module object >>> old_binascii == binascii False
As a rule of thumb, the two modules should be completely independent. All objects and state specific to the module should be encapsulated
within the mod... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
02444e1e-3d75-4100-8dac-98b9657e97d6 | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,928 | supabase-export-v2 | bca44ef767c02bbd | return the module of the true defining class. However, it will always return a module with the same definition, ensuring a compatible C memory layout.
Lifetime of the Module State
---------------------------- | trusted_official_docs | CPython Docs | return the module of the true defining class. However, it will always return a module with the same definition, ensuring a compatible C memory layout.
Lifetime of the Module State
---------------------------- | return the module of the true defining class. However, it will always return a module with the same definition, ensuring a compatible C memory layout.
Lifetime of the Module State
---------------------------- | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
08d0c1df-9d21-44ad-add1-8ad32a74ccc3 | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,925 | supabase-export-v2 | 6ac5d84a75667e34 | PyObject *module = PyType_GetModuleByDef(Py_TYPE(self), &module_def); my_struct *state = (my_struct*)PyModule_GetState(module); if (state == NULL) { return NULL; }
:c:func:`!PyType_GetModuleByDef` works by searching the
:term:`method resolution order` (i.e. all superclasses) for the first
superclass that has a correspo... | trusted_official_docs | CPython Docs | PyObject *module = PyType_GetModuleByDef(Py_TYPE(self), &module_def); my_struct *state = (my_struct*)PyModule_GetState(module); if (state == NULL) { return NULL; }
:c:func:`!PyType_GetModuleByDef` works by searching the
:term:`method resolution order` (i.e. all superclasses) for the first
superclass that has a correspo... | PyObject *module = PyType_GetModuleByDef(Py_TYPE(self), &module_def); my_struct *state = (my_struct*)PyModule_GetState(module); if (state == NULL) { return NULL; }
:c:func:`!PyType_GetModuleByDef` works by searching the
:term:`method resolution order` (i.e. all superclasses) for the first
superclass that has a correspo... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0c03b1cc-9453-4245-a555-71385b4b4703 | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,804 | supabase-export-v2 | 63cd14ef2f0ba744 | *interpreter* is the context in which Python code runs. It contains configuration (e.g. the import path) and runtime state (e.g. the set of imported modules).
Python supports running multiple interpreters in one process. There are
two cases to think about—users may run interpreters: | trusted_official_docs | CPython Docs | *interpreter* is the context in which Python code runs. It contains configuration (e.g. the import path) and runtime state (e.g. the set of imported modules).
Python supports running multiple interpreters in one process. There are
two cases to think about—users may run interpreters: | *interpreter* is the context in which Python code runs. It contains configuration (e.g. the import path) and runtime state (e.g. the set of imported modules).
Python supports running multiple interpreters in one process. There are
two cases to think about—users may run interpreters: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0e349052-393b-44d1-b9de-93eecb190ffe | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,871 | supabase-export-v2 | e30c2817a5b8ef4f | added in Python 3.9. If you support Python 3.8 and lower, the traverse function must *not* visit the type, so it must be more complicated::
static int my_traverse(PyObject *self, visitproc visit, void *arg)
{
if (Py_Version >= 0x03090000) {
Py_VISIT(Py_TYPE(self));
}
return 0;
} | trusted_official_docs | CPython Docs | added in Python 3.9. If you support Python 3.8 and lower, the traverse function must *not* visit the type, so it must be more complicated::
static int my_traverse(PyObject *self, visitproc visit, void *arg)
{
if (Py_Version >= 0x03090000) {
Py_VISIT(Py_TYPE(self));
}
return 0;
} | added in Python 3.9. If you support Python 3.8 and lower, the traverse function must *not* visit the type, so it must be more complicated::
static int my_traverse(PyObject *self, visitproc visit, void *arg)
{
if (Py_Version >= 0x03090000) {
Py_VISIT(Py_TYPE(self));
}
return 0;
} | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0e87570a-1d4c-4d1f-8b51-5ef96af38340 | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,869 | supabase-export-v2 | d570e8a7d6f29b0b | for defining heap types grew organically, leaving it somewhat awkward to use in its current state. The following sections will guide you through common issues.
``tp_traverse`` in Python 3.8 and lower
....................................... | trusted_official_docs | CPython Docs | for defining heap types grew organically, leaving it somewhat awkward to use in its current state. The following sections will guide you through common issues.
``tp_traverse`` in Python 3.8 and lower
....................................... | for defining heap types grew organically, leaving it somewhat awkward to use in its current state. The following sections will guide you through common issues.
``tp_traverse`` in Python 3.8 and lower
....................................... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
115e77ac-fabc-4249-92a1-bfb3c4479511 | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,834 | supabase-export-v2 | 6390045679d459aa | where you should put pointers to classes (including exceptions, but excluding static types) and settings (e.g. ``csv``'s :py:data:`~csv.field_size_limit`) which the C code needs to function.
.. note::
Another option is to store state in the module's ``__dict__``,
but you must avoid crashing when users modify ``__dict... | trusted_official_docs | CPython Docs | where you should put pointers to classes (including exceptions, but excluding static types) and settings (e.g. ``csv``'s :py:data:`~csv.field_size_limit`) which the C code needs to function.
.. note::
Another option is to store state in the module's ``__dict__``,
but you must avoid crashing when users modify ``__dict... | where you should put pointers to classes (including exceptions, but excluding static types) and settings (e.g. ``csv``'s :py:data:`~csv.field_size_limit`) which the C code needs to function.
.. note::
Another option is to store state in the module's ``__dict__``,
but you must avoid crashing when users modify ``__dict... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
14ac7af7-206e-4d53-a7ee-c035d9dcd50a | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,846 | supabase-export-v2 | 3c3b4ddddf38db75 | Module State Access from Functions ----------------------------------
Accessing the state from module-level functions is straightforward. Functions get the module object as their first argument; for extracting
the state, you can use ``PyModule_GetState``:: | trusted_official_docs | CPython Docs | Module State Access from Functions ----------------------------------
Accessing the state from module-level functions is straightforward. Functions get the module object as their first argument; for extracting
the state, you can use ``PyModule_GetState``:: | Module State Access from Functions ----------------------------------
Accessing the state from module-level functions is straightforward. Functions get the module object as their first argument; for extracting
the state, you can use ``PyModule_GetState``:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1671fbe7-73dc-4372-b0ff-a54bb654984a | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,810 | supabase-export-v2 | cabf467768a3b87f | Enter Per-Module State ----------------------
Instead of focusing on per-interpreter state, Python's C API is evolving
to better support the more granular *per-module* state. This means that C-level data should be attached to a *module object*. Each interpreter creates its own module object, keeping the data separate. ... | trusted_official_docs | CPython Docs | Enter Per-Module State ----------------------
Instead of focusing on per-interpreter state, Python's C API is evolving
to better support the more granular *per-module* state. This means that C-level data should be attached to a *module object*. Each interpreter creates its own module object, keeping the data separate. ... | Enter Per-Module State ----------------------
Instead of focusing on per-interpreter state, Python's C API is evolving
to better support the more granular *per-module* state. This means that C-level data should be attached to a *module object*. Each interpreter creates its own module object, keeping the data separate. ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
177a4e3f-31ef-4b2f-bace-6fc222743b7d | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,829 | supabase-export-v2 | 17a6ba4df73c2953 | - The ``readline`` module manages *the* terminal. - A module running on a circuit board wants to control *the* on-board LED.
In these cases, the Python module should provide *access* to the global
state, rather than *own* it. If possible, write the module so that
multiple copies of it can access the state independently... | trusted_official_docs | CPython Docs | - The ``readline`` module manages *the* terminal. - A module running on a circuit board wants to control *the* on-board LED.
In these cases, the Python module should provide *access* to the global
state, rather than *own* it. If possible, write the module so that
multiple copies of it can access the state independently... | - The ``readline`` module manages *the* terminal. - A module running on a circuit board wants to control *the* on-board LED.
In these cases, the Python module should provide *access* to the global
state, rather than *own* it. If possible, write the module so that
multiple copies of it can access the state independently... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1b4655f9-1f58-433b-ad0f-461008024ee5 | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,870 | supabase-export-v2 | f6d976ba4d46ac8a | ``tp_traverse`` in Python 3.8 and lower .......................................
The requirement to visit the type from ``tp_traverse`` was added in Python 3.9. If you support Python 3.8 and lower, the traverse function must *not*
visit the type, so it must be more complicated:: | trusted_official_docs | CPython Docs | ``tp_traverse`` in Python 3.8 and lower .......................................
The requirement to visit the type from ``tp_traverse`` was added in Python 3.9. If you support Python 3.8 and lower, the traverse function must *not*
visit the type, so it must be more complicated:: | ``tp_traverse`` in Python 3.8 and lower .......................................
The requirement to visit the type from ``tp_traverse`` was added in Python 3.9. If you support Python 3.8 and lower, the traverse function must *not*
visit the type, so it must be more complicated:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1c450298-9ae7-48a8-b128-46a5476cfa24 | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,822 | supabase-export-v2 | 15fc418056b27796 | .. code-block:: pycon
>>> old_binascii.Error == binascii.Error
False
>>> try:
... old_binascii.unhexlify(b'qwertyuiop')
... except binascii.Error:
... print('boo')
... Traceback (most recent call last):
File "<stdin>", line 2, in <module>
binascii.Error: Non-hexadecimal digit found | trusted_official_docs | CPython Docs | .. code-block:: pycon
>>> old_binascii.Error == binascii.Error
False
>>> try:
... old_binascii.unhexlify(b'qwertyuiop')
... except binascii.Error:
... print('boo')
... Traceback (most recent call last):
File "<stdin>", line 2, in <module>
binascii.Error: Non-hexadecimal digit found | .. code-block:: pycon
>>> old_binascii.Error == binascii.Error
False
>>> try:
... old_binascii.unhexlify(b'qwertyuiop')
... except binascii.Error:
... print('boo')
... Traceback (most recent call last):
File "<stdin>", line 2, in <module>
binascii.Error: Non-hexadecimal digit found | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1d0ceea3-6225-415b-a4dd-fd234540f313 | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,936 | supabase-export-v2 | 2433eb602fa63944 | state to individual *types* without relying on CPython implementation details (which may change in the future—perhaps, ironically, to allow a proper solution for per-class scope).
Lossless Conversion to Heap Types
--------------------------------- | trusted_official_docs | CPython Docs | state to individual *types* without relying on CPython implementation details (which may change in the future—perhaps, ironically, to allow a proper solution for per-class scope).
Lossless Conversion to Heap Types
--------------------------------- | state to individual *types* without relying on CPython implementation details (which may change in the future—perhaps, ironically, to allow a proper solution for per-class scope).
Lossless Conversion to Heap Types
--------------------------------- | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
260db131-5ed8-4c89-a619-9aa5e8370aae | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,865 | supabase-export-v2 | 45717563969942f9 | that the type isn't destroyed before all its instances are, but may result in reference cycles that need to be broken by the garbage collector.
To avoid memory leaks, instances of heap types must implement the
garbage collection protocol. That is, heap types should: | trusted_official_docs | CPython Docs | that the type isn't destroyed before all its instances are, but may result in reference cycles that need to be broken by the garbage collector.
To avoid memory leaks, instances of heap types must implement the
garbage collection protocol. That is, heap types should: | that the type isn't destroyed before all its instances are, but may result in reference cycles that need to be broken by the garbage collector.
To avoid memory leaks, instances of heap types must implement the
garbage collection protocol. That is, heap types should: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2b6852a2-fc62-4292-8036-23c7c598c4ca | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,801 | supabase-export-v2 | 255b4d0d63a7e8f1 | Who should read this ====================
This guide is written for maintainers of :ref:`C-API <c-api-index>` extensions
who would like to make that extension safer to use in applications where
Python itself is used as a library. | trusted_official_docs | CPython Docs | Who should read this ====================
This guide is written for maintainers of :ref:`C-API <c-api-index>` extensions
who would like to make that extension safer to use in applications where
Python itself is used as a library. | Who should read this ====================
This guide is written for maintainers of :ref:`C-API <c-api-index>` extensions
who would like to make that extension safer to use in applications where
Python itself is used as a library. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2c3c18e0-2c9f-4a1b-91db-38fde0caafda | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,847 | supabase-export-v2 | cdb6d4f5249ef07b | Accessing the state from module-level functions is straightforward. Functions get the module object as their first argument; for extracting the state, you can use ``PyModule_GetState``::
static PyObject *
func(PyObject *module, PyObject *args)
{
my_struct *state = (my_struct*)PyModule_GetState(module);
if (state ==... | trusted_official_docs | CPython Docs | Accessing the state from module-level functions is straightforward. Functions get the module object as their first argument; for extracting the state, you can use ``PyModule_GetState``::
static PyObject *
func(PyObject *module, PyObject *args)
{
my_struct *state = (my_struct*)PyModule_GetState(module);
if (state ==... | Accessing the state from module-level functions is straightforward. Functions get the module object as their first argument; for extracting the state, you can use ``PyModule_GetState``::
static PyObject *
func(PyObject *module, PyObject *args)
{
my_struct *state = (my_struct*)PyModule_GetState(module);
if (state ==... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
33abd9f8-1f03-49a1-a90d-49480e005db3 | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,904 | supabase-export-v2 | 2abf664c14748c98 | API introduced in Python 3.9. To get the state, you need to first get the *defining class*, and then get the module state from it.
The largest roadblock is getting *the class a method was defined in*, or
that method's "defining class" for short. The defining class can have a
reference to the module it is part of. | trusted_official_docs | CPython Docs | API introduced in Python 3.9. To get the state, you need to first get the *defining class*, and then get the module state from it.
The largest roadblock is getting *the class a method was defined in*, or
that method's "defining class" for short. The defining class can have a
reference to the module it is part of. | API introduced in Python 3.9. To get the state, you need to first get the *defining class*, and then get the module state from it.
The largest roadblock is getting *the class a method was defined in*, or
that method's "defining class" for short. The defining class can have a
reference to the module it is part of. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
34661a6c-9758-42d0-921d-0c057d7688f9 | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,927 | supabase-export-v2 | ecadf4fbdab7fa55 | .. note::
In very exotic cases (inheritance chains spanning multiple modules
created from the same definition), :c:func:`!PyType_GetModuleByDef` might not
return the module of the true defining class. However, it will always
return a module with the same definition, ensuring a compatible
C memory layout. | trusted_official_docs | CPython Docs | .. note::
In very exotic cases (inheritance chains spanning multiple modules
created from the same definition), :c:func:`!PyType_GetModuleByDef` might not
return the module of the true defining class. However, it will always
return a module with the same definition, ensuring a compatible
C memory layout. | .. note::
In very exotic cases (inheritance chains spanning multiple modules
created from the same definition), :c:func:`!PyType_GetModuleByDef` might not
return the module of the true defining class. However, it will always
return a module with the same definition, ensuring a compatible
C memory layout. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
367e1a0e-fd2f-4712-b2e4-a13f9e5a0104 | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,867 | supabase-export-v2 | 1766bf5026d3f462 | - Have the :c:macro:`Py_TPFLAGS_HAVE_GC` flag. - Define a traverse function using :c:data:`Py_tp_traverse`, which visits the type (e.g. using ``Py_VISIT(Py_TYPE(self))``).
Please refer to the documentation of
:c:macro:`Py_TPFLAGS_HAVE_GC` and :c:member:`~PyTypeObject.tp_traverse`
for additional considerations. | trusted_official_docs | CPython Docs | - Have the :c:macro:`Py_TPFLAGS_HAVE_GC` flag. - Define a traverse function using :c:data:`Py_tp_traverse`, which visits the type (e.g. using ``Py_VISIT(Py_TYPE(self))``).
Please refer to the documentation of
:c:macro:`Py_TPFLAGS_HAVE_GC` and :c:member:`~PyTypeObject.tp_traverse`
for additional considerations. | - Have the :c:macro:`Py_TPFLAGS_HAVE_GC` flag. - Define a traverse function using :c:data:`Py_tp_traverse`, which visits the type (e.g. using ``Py_VISIT(Py_TYPE(self))``).
Please refer to the documentation of
:c:macro:`Py_TPFLAGS_HAVE_GC` and :c:member:`~PyTypeObject.tp_traverse`
for additional considerations. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
38032e1d-0c9f-4e26-819e-9cb30ed0116c | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,880 | supabase-export-v2 | f6a7730c47c944eb | if (base->tp_flags & Py_TPFLAGS_HEAPTYPE) { // a heap type's tp_traverse already visited Py_TYPE(self) } else { if (Py_Version >= 0x03090000) { Py_VISIT(Py_TYPE(self)); } }
It is not necessary to handle the type's reference count in
:c:member:`~PyTypeObject.tp_new` and :c:member:`~PyTypeObject.tp_clear`. | trusted_official_docs | CPython Docs | if (base->tp_flags & Py_TPFLAGS_HEAPTYPE) { // a heap type's tp_traverse already visited Py_TYPE(self) } else { if (Py_Version >= 0x03090000) { Py_VISIT(Py_TYPE(self)); } }
It is not necessary to handle the type's reference count in
:c:member:`~PyTypeObject.tp_new` and :c:member:`~PyTypeObject.tp_clear`. | if (base->tp_flags & Py_TPFLAGS_HEAPTYPE) { // a heap type's tp_traverse already visited Py_TYPE(self) } else { if (Py_Version >= 0x03090000) { Py_VISIT(Py_TYPE(self)); } }
It is not necessary to handle the type's reference count in
:c:member:`~PyTypeObject.tp_new` and :c:member:`~PyTypeObject.tp_clear`. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
40b65d6c-d510-462c-a188-7bcff6733b2a | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,876 | supabase-export-v2 | cb57219823dab38e | base class (or another type), ensure that ``Py_TYPE(self)`` is visited only once. Note that only heap type are expected to visit the type in ``tp_traverse``.
For example, if your traverse function includes:: | trusted_official_docs | CPython Docs | base class (or another type), ensure that ``Py_TYPE(self)`` is visited only once. Note that only heap type are expected to visit the type in ``tp_traverse``.
For example, if your traverse function includes:: | base class (or another type), ensure that ``Py_TYPE(self)`` is visited only once. Note that only heap type are expected to visit the type in ``tp_traverse``.
For example, if your traverse function includes:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
42d1e184-13c2-4a60-9d24-4632b4f6f64e | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,841 | supabase-export-v2 | e4acfeb5c6c330ef | interpreters correctly. If this is not yet the case for your module, you can explicitly make your module loadable only once per process. For example::
// A process-wide flag
static int loaded = 0; | trusted_official_docs | CPython Docs | interpreters correctly. If this is not yet the case for your module, you can explicitly make your module loadable only once per process. For example::
// A process-wide flag
static int loaded = 0; | interpreters correctly. If this is not yet the case for your module, you can explicitly make your module loadable only once per process. For example::
// A process-wide flag
static int loaded = 0; | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
445d239d-1cd4-4e89-992a-810f14bac009 | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,845 | supabase-export-v2 | 644a6c4ef9fc1a0d | case, your module won't support multiple instances existing *concurrently*, but it will, for example, support being loaded after Python runtime shutdown (:c:func:`Py_FinalizeEx`) and re-initialization (:c:func:`Py_Initialize`).
Module State Access from Functions
---------------------------------- | trusted_official_docs | CPython Docs | case, your module won't support multiple instances existing *concurrently*, but it will, for example, support being loaded after Python runtime shutdown (:c:func:`Py_FinalizeEx`) and re-initialization (:c:func:`Py_Initialize`).
Module State Access from Functions
---------------------------------- | case, your module won't support multiple instances existing *concurrently*, but it will, for example, support being loaded after Python runtime shutdown (:c:func:`Py_FinalizeEx`) and re-initialization (:c:func:`Py_Initialize`).
Module State Access from Functions
---------------------------------- | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
456c3ee5-c7cc-4744-be72-e30f7a024d15 | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,820 | supabase-export-v2 | 0a83157509d9bff4 | Surprising Edge Cases ---------------------
Note that isolated modules do create some surprising edge cases. Most
notably, each module object will typically not share its classes and
exceptions with other similar modules. Continuing from the
`example above <Isolated Module Objects_>`__,
note that ``old_binascii.Error``... | trusted_official_docs | CPython Docs | Surprising Edge Cases ---------------------
Note that isolated modules do create some surprising edge cases. Most
notably, each module object will typically not share its classes and
exceptions with other similar modules. Continuing from the
`example above <Isolated Module Objects_>`__,
note that ``old_binascii.Error``... | Surprising Edge Cases ---------------------
Note that isolated modules do create some surprising edge cases. Most
notably, each module object will typically not share its classes and
exceptions with other similar modules. Continuing from the
`example above <Isolated Module Objects_>`__,
note that ``old_binascii.Error``... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
47821a11-8620-4ade-9e6f-b0450fff8fff | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,903 | supabase-export-v2 | f1d39112e49bbd86 | Module State Access from Regular Methods ----------------------------------------
Accessing the module-level state from methods of a class is somewhat more
complicated, but is possible thanks to API introduced in Python 3.9. To get the state, you need to first get the *defining class*, and then
get the module state fro... | trusted_official_docs | CPython Docs | Module State Access from Regular Methods ----------------------------------------
Accessing the module-level state from methods of a class is somewhat more
complicated, but is possible thanks to API introduced in Python 3.9. To get the state, you need to first get the *defining class*, and then
get the module state fro... | Module State Access from Regular Methods ----------------------------------------
Accessing the module-level state from methods of a class is somewhat more
complicated, but is possible thanks to API introduced in Python 3.9. To get the state, you need to first get the *defining class*, and then
get the module state fro... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
48eb2f07-af74-4516-b2c9-88d854d11a56 | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,830 | supabase-export-v2 | a54a9bb681271209 | of it can access the state independently (along with other libraries, whether for Python or other languages). If that is not possible, consider explicit locking.
If it is necessary to use process-global state, the simplest way to
avoid issues with multiple interpreters is to explicitly prevent a
module from being loade... | trusted_official_docs | CPython Docs | of it can access the state independently (along with other libraries, whether for Python or other languages). If that is not possible, consider explicit locking.
If it is necessary to use process-global state, the simplest way to
avoid issues with multiple interpreters is to explicitly prevent a
module from being loade... | of it can access the state independently (along with other libraries, whether for Python or other languages). If that is not possible, consider explicit locking.
If it is necessary to use process-global state, the simplest way to
avoid issues with multiple interpreters is to explicitly prevent a
module from being loade... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
49a359a0-f336-4ba1-9425-481570640f3e | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,906 | supabase-export-v2 | 81de8a283a1b93ac | the method is called on a *subclass* of your type, ``Py_TYPE(self)`` will refer to that subclass, which may be defined in different module than yours.
.. note::
The following Python code can illustrate the concept. ``Base.get_defining_class`` returns ``Base`` even
if ``type(self) == Sub``: | trusted_official_docs | CPython Docs | the method is called on a *subclass* of your type, ``Py_TYPE(self)`` will refer to that subclass, which may be defined in different module than yours.
.. note::
The following Python code can illustrate the concept. ``Base.get_defining_class`` returns ``Base`` even
if ``type(self) == Sub``: | the method is called on a *subclass* of your type, ``Py_TYPE(self)`` will refer to that subclass, which may be defined in different module than yours.
.. note::
The following Python code can illustrate the concept. ``Base.get_defining_class`` returns ``Base`` even
if ``type(self) == Sub``: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4a7bf05a-5354-4c5c-b289-bfbe009776c8 | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,913 | supabase-export-v2 | 0535ecf11a736a34 | defining class PyObject *const *args, // C array of arguments Py_ssize_t nargs, // length of "args" PyObject *kwnames) // NULL, or dict of keyword arguments
Once you have the defining class, call :c:func:`PyType_GetModuleState` to get
the state of its associated module. | trusted_official_docs | CPython Docs | defining class PyObject *const *args, // C array of arguments Py_ssize_t nargs, // length of "args" PyObject *kwnames) // NULL, or dict of keyword arguments
Once you have the defining class, call :c:func:`PyType_GetModuleState` to get
the state of its associated module. | defining class PyObject *const *args, // C array of arguments Py_ssize_t nargs, // length of "args" PyObject *kwnames) // NULL, or dict of keyword arguments
Once you have the defining class, call :c:func:`PyType_GetModuleState` to get
the state of its associated module. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4f5bcad7-2f8f-4f97-8be5-8b1487d68c20 | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,860 | supabase-export-v2 | 61b1d21dd50ea6e0 | Defining Heap Types -------------------
Heap types can be created by filling a :c:struct:`PyType_Spec` structure, a
description or "blueprint" of a class, and calling
:c:func:`PyType_FromModuleAndSpec` to construct a new class object. | trusted_official_docs | CPython Docs | Defining Heap Types -------------------
Heap types can be created by filling a :c:struct:`PyType_Spec` structure, a
description or "blueprint" of a class, and calling
:c:func:`PyType_FromModuleAndSpec` to construct a new class object. | Defining Heap Types -------------------
Heap types can be created by filling a :c:struct:`PyType_Spec` structure, a
description or "blueprint" of a class, and calling
:c:func:`PyType_FromModuleAndSpec` to construct a new class object. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
53412236-3a5e-4281-88e3-fe537e168c59 | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,915 | supabase-export-v2 | 27d1ec58e49a26ce | For example::
static PyObject *
example_method(PyObject *self,
PyTypeObject *defining_class,
PyObject *const *args,
Py_ssize_t nargs,
PyObject *kwnames)
{
my_struct *state = (my_struct*)PyType_GetModuleState(defining_class);
if (state == NULL) {
return NULL;
}
... // rest of logic
} | trusted_official_docs | CPython Docs | For example::
static PyObject *
example_method(PyObject *self,
PyTypeObject *defining_class,
PyObject *const *args,
Py_ssize_t nargs,
PyObject *kwnames)
{
my_struct *state = (my_struct*)PyType_GetModuleState(defining_class);
if (state == NULL) {
return NULL;
}
... // rest of logic
} | For example::
static PyObject *
example_method(PyObject *self,
PyTypeObject *defining_class,
PyObject *const *args,
Py_ssize_t nargs,
PyObject *kwnames)
{
my_struct *state = (my_struct*)PyType_GetModuleState(defining_class);
if (state == NULL) {
return NULL;
}
... // rest of logic
} | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
54c14aeb-9684-49a1-bd43-487aa2a2d20f | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,875 | supabase-export-v2 | f64843b30eee3912 | Delegating ``tp_traverse`` ..........................
If your traverse function delegates to the :c:member:`~PyTypeObject.tp_traverse`
of its base class (or another type), ensure that ``Py_TYPE(self)`` is visited
only once. Note that only heap type are expected to visit the type in ``tp_traverse``. | trusted_official_docs | CPython Docs | Delegating ``tp_traverse`` ..........................
If your traverse function delegates to the :c:member:`~PyTypeObject.tp_traverse`
of its base class (or another type), ensure that ``Py_TYPE(self)`` is visited
only once. Note that only heap type are expected to visit the type in ``tp_traverse``. | Delegating ``tp_traverse`` ..........................
If your traverse function delegates to the :c:member:`~PyTypeObject.tp_traverse`
of its base class (or another type), ensure that ``Py_TYPE(self)`` is visited
only once. Note that only heap type are expected to visit the type in ``tp_traverse``. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5842a86c-296d-486f-9e7a-dc93190dc9d2 | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,798 | supabase-export-v2 | 46248931a1f48d1b | .. topic:: Abstract
Traditionally, state belonging to Python extension modules was kept in C
``static`` variables, which have process-wide scope. This document
describes problems of such per-process state and shows a safer way:
per-module state. | trusted_official_docs | CPython Docs | .. topic:: Abstract
Traditionally, state belonging to Python extension modules was kept in C
``static`` variables, which have process-wide scope. This document
describes problems of such per-process state and shows a safer way:
per-module state. | .. topic:: Abstract
Traditionally, state belonging to Python extension modules was kept in C
``static`` variables, which have process-wide scope. This document
describes problems of such per-process state and shows a safer way:
per-module state. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5a3437f6-b8d2-451d-ad03-e1d734d14876 | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,930 | supabase-export-v2 | 1e275692f1894691 | garbage-collected, its module state is freed. For each pointer to (a part of) the module state, you must hold a reference to the module object.
Usually this is not an issue, because types created with
:c:func:`PyType_FromModuleAndSpec`, and their instances, hold a reference
to the module. However, you must be careful i... | trusted_official_docs | CPython Docs | garbage-collected, its module state is freed. For each pointer to (a part of) the module state, you must hold a reference to the module object.
Usually this is not an issue, because types created with
:c:func:`PyType_FromModuleAndSpec`, and their instances, hold a reference
to the module. However, you must be careful i... | garbage-collected, its module state is freed. For each pointer to (a part of) the module state, you must hold a reference to the module object.
Usually this is not an issue, because types created with
:c:func:`PyType_FromModuleAndSpec`, and their instances, hold a reference
to the module. However, you must be careful i... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5cfbf5a0-1807-400c-8d2c-5831903d3351 | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,857 | supabase-export-v2 | ea4f45eb28be5c7b | new API, you are likely to unintentionally change a few details (e.g. pickleability or inherited slots). Always test the details that are important to you.
Watch out for the following two points in particular (but note that this is not
a comprehensive list): | trusted_official_docs | CPython Docs | new API, you are likely to unintentionally change a few details (e.g. pickleability or inherited slots). Always test the details that are important to you.
Watch out for the following two points in particular (but note that this is not
a comprehensive list): | new API, you are likely to unintentionally change a few details (e.g. pickleability or inherited slots). Always test the details that are important to you.
Watch out for the following two points in particular (but note that this is not
a comprehensive list): | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5db20b97-c41b-4441-b715-ba207c7bdc3d | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,823 | supabase-export-v2 | ea143fcf2285e81d | >>> try: ... old_binascii.unhexlify(b'qwertyuiop') ... except binascii.Error: ... print('boo') ... Traceback (most recent call last): File "<stdin>", line 2, in <module> binascii.Error: Non-hexadecimal digit found
This is expected. Notice that pure-Python modules behave the same way:
it is a part of how Python works. | trusted_official_docs | CPython Docs | >>> try: ... old_binascii.unhexlify(b'qwertyuiop') ... except binascii.Error: ... print('boo') ... Traceback (most recent call last): File "<stdin>", line 2, in <module> binascii.Error: Non-hexadecimal digit found
This is expected. Notice that pure-Python modules behave the same way:
it is a part of how Python works. | >>> try: ... old_binascii.unhexlify(b'qwertyuiop') ... except binascii.Error: ... print('boo') ... Traceback (most recent call last): File "<stdin>", line 2, in <module> binascii.Error: Non-hexadecimal digit found
This is expected. Notice that pure-Python modules behave the same way:
it is a part of how Python works. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5ea3abd8-ca03-485f-b58c-15c34925ef71 | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,800 | supabase-export-v2 | 39c73c89babc0f59 | where possible. This transition involves allocating space for that state, potentially switching from static types to heap types, and—perhaps most importantly—accessing per-module state from code.
Who should read this
==================== | trusted_official_docs | CPython Docs | where possible. This transition involves allocating space for that state, potentially switching from static types to heap types, and—perhaps most importantly—accessing per-module state from code.
Who should read this
==================== | where possible. This transition involves allocating space for that state, potentially switching from static types to heap types, and—perhaps most importantly—accessing per-module state from code.
Who should read this
==================== | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
62ab6093-1ee9-4d92-a517-1a10e139aaf1 | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,922 | supabase-export-v2 | 91f7294a048efa4b | If you use the :ref:`limited API <limited-c-api>`, you must update ``Py_LIMITED_API`` to ``0x030b0000``, losing ABI compatibility with earlier versions.
Slot methods—the fast C equivalents for special methods, such as
:c:member:`~PyNumberMethods.nb_add` for :py:attr:`~object.__add__` or
:c:member:`~PyTypeObject.tp_new`... | trusted_official_docs | CPython Docs | If you use the :ref:`limited API <limited-c-api>`, you must update ``Py_LIMITED_API`` to ``0x030b0000``, losing ABI compatibility with earlier versions.
Slot methods—the fast C equivalents for special methods, such as
:c:member:`~PyNumberMethods.nb_add` for :py:attr:`~object.__add__` or
:c:member:`~PyTypeObject.tp_new`... | If you use the :ref:`limited API <limited-c-api>`, you must update ``Py_LIMITED_API`` to ``0x030b0000``, losing ABI compatibility with earlier versions.
Slot methods—the fast C equivalents for special methods, such as
:c:member:`~PyNumberMethods.nb_add` for :py:attr:`~object.__add__` or
:c:member:`~PyTypeObject.tp_new`... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
64576835-63df-43a2-95bf-96bbb12e4f41 | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,807 | supabase-export-v2 | ea391e60ea425d89 | when embedding Python within a library. Libraries generally shouldn't make assumptions about the application that uses them, which include assuming a process-wide "main Python interpreter".
Historically, Python extension modules don't handle this use case well. Many extension modules (and even some stdlib modules) use ... | trusted_official_docs | CPython Docs | when embedding Python within a library. Libraries generally shouldn't make assumptions about the application that uses them, which include assuming a process-wide "main Python interpreter".
Historically, Python extension modules don't handle this use case well. Many extension modules (and even some stdlib modules) use ... | when embedding Python within a library. Libraries generally shouldn't make assumptions about the application that uses them, which include assuming a process-wide "main Python interpreter".
Historically, Python extension modules don't handle this use case well. Many extension modules (and even some stdlib modules) use ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
65ef5486-267b-44fa-af4d-39b6fab4731f | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,868 | supabase-export-v2 | 5678ec708437016c | Please refer to the documentation of :c:macro:`Py_TPFLAGS_HAVE_GC` and :c:member:`~PyTypeObject.tp_traverse` for additional considerations.
The API for defining heap types grew organically, leaving it
somewhat awkward to use in its current state. The following sections will guide you through common issues. | trusted_official_docs | CPython Docs | Please refer to the documentation of :c:macro:`Py_TPFLAGS_HAVE_GC` and :c:member:`~PyTypeObject.tp_traverse` for additional considerations.
The API for defining heap types grew organically, leaving it
somewhat awkward to use in its current state. The following sections will guide you through common issues. | Please refer to the documentation of :c:macro:`Py_TPFLAGS_HAVE_GC` and :c:member:`~PyTypeObject.tp_traverse` for additional considerations.
The API for defining heap types grew organically, leaving it
somewhat awkward to use in its current state. The following sections will guide you through common issues. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
66810ed2-fb9d-4486-8b45-4d4eb31a904f | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,851 | supabase-export-v2 | 817a330549934998 | Traditionally, types defined in C code are *static*; that is, ``static PyTypeObject`` structures defined directly in code and initialized using ``PyType_Ready()``.
Such types are necessarily shared across the process. Sharing them
between module objects requires paying attention to any state they own
or access. To limi... | trusted_official_docs | CPython Docs | Traditionally, types defined in C code are *static*; that is, ``static PyTypeObject`` structures defined directly in code and initialized using ``PyType_Ready()``.
Such types are necessarily shared across the process. Sharing them
between module objects requires paying attention to any state they own
or access. To limi... | Traditionally, types defined in C code are *static*; that is, ``static PyTypeObject`` structures defined directly in code and initialized using ``PyType_Ready()``.
Such types are necessarily shared across the process. Sharing them
between module objects requires paying attention to any state they own
or access. To limi... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
67728947-a478-40fa-a446-7ec2d49cb65a | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,799 | supabase-export-v2 | 3f21ac9454858f7b | was kept in C ``static`` variables, which have process-wide scope. This document describes problems of such per-process state and shows a safer way: per-module state.
The document also describes how to switch to per-module state where
possible. This transition involves allocating space for that state, potentially
swi... | trusted_official_docs | CPython Docs | was kept in C ``static`` variables, which have process-wide scope. This document describes problems of such per-process state and shows a safer way: per-module state.
The document also describes how to switch to per-module state where
possible. This transition involves allocating space for that state, potentially
swi... | was kept in C ``static`` variables, which have process-wide scope. This document describes problems of such per-process state and shows a safer way: per-module state.
The document also describes how to switch to per-module state where
possible. This transition involves allocating space for that state, potentially
swi... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6a42e13d-71f4-45b9-b34e-e091631056a2 | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,905 | supabase-export-v2 | e1c3c419bd0a6f71 | method was defined in*, or that method's "defining class" for short. The defining class can have a reference to the module it is part of.
Do not confuse the defining class with ``Py_TYPE(self)``. If the method
is called on a *subclass* of your type, ``Py_TYPE(self)`` will refer to
that subclass, which may be defined in... | trusted_official_docs | CPython Docs | method was defined in*, or that method's "defining class" for short. The defining class can have a reference to the module it is part of.
Do not confuse the defining class with ``Py_TYPE(self)``. If the method
is called on a *subclass* of your type, ``Py_TYPE(self)`` will refer to
that subclass, which may be defined in... | method was defined in*, or that method's "defining class" for short. The defining class can have a reference to the module it is part of.
Do not confuse the defining class with ``Py_TYPE(self)``. If the method
is called on a *subclass* of your type, ``Py_TYPE(self)`` will refer to
that subclass, which may be defined in... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6c2cc0a9-eeb4-42f3-a914-c4258c8868eb | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,885 | supabase-export-v2 | 73cac3a7dcb95f08 | To keep the type valid while ``tp_free`` is called, the type's refcount needs to be decremented *after* the instance is deallocated. For example::
static void my_dealloc(PyObject *self)
{
PyObject_GC_UnTrack(self);
... PyTypeObject *type = Py_TYPE(self);
type->tp_free(self);
Py_DECREF(type);
} | trusted_official_docs | CPython Docs | To keep the type valid while ``tp_free`` is called, the type's refcount needs to be decremented *after* the instance is deallocated. For example::
static void my_dealloc(PyObject *self)
{
PyObject_GC_UnTrack(self);
... PyTypeObject *type = Py_TYPE(self);
type->tp_free(self);
Py_DECREF(type);
} | To keep the type valid while ``tp_free`` is called, the type's refcount needs to be decremented *after* the instance is deallocated. For example::
static void my_dealloc(PyObject *self)
{
PyObject_GC_UnTrack(self);
... PyTypeObject *type = Py_TYPE(self);
type->tp_free(self);
Py_DECREF(type);
} | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6fd1c84e-7541-4be6-897d-f9d0e7a92d2c | CPython Docs | file://datasets/cpython/Doc/howto/isolating-extensions.rst | unknown | bd76972e-a00c-40c6-8eea-2a893a040e88 | 57,861 | supabase-export-v2 | b0969b9dbd1ba226 | types can be created by filling a :c:struct:`PyType_Spec` structure, a description or "blueprint" of a class, and calling :c:func:`PyType_FromModuleAndSpec` to construct a new class object.
.. note::
Other functions, like :c:func:`PyType_FromSpec`, can also create
heap types, but :c:func:`PyType_FromModuleAndSpec` as... | trusted_official_docs | CPython Docs | types can be created by filling a :c:struct:`PyType_Spec` structure, a description or "blueprint" of a class, and calling :c:func:`PyType_FromModuleAndSpec` to construct a new class object.
.. note::
Other functions, like :c:func:`PyType_FromSpec`, can also create
heap types, but :c:func:`PyType_FromModuleAndSpec` as... | types can be created by filling a :c:struct:`PyType_Spec` structure, a description or "blueprint" of a class, and calling :c:func:`PyType_FromModuleAndSpec` to construct a new class object.
.. note::
Other functions, like :c:func:`PyType_FromSpec`, can also create
heap types, but :c:func:`PyType_FromModuleAndSpec` as... | python, official-docs, cpython, P0 | Local_Trusted_Corpus |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.