Python Glossary Русский

Python 3.14+sysfunction

sys.remote_exec()

debugging and tracing

Asks another Python process of the same version to run a script file at the next opportunity. The basis for attaching a debugger to a live process (3.14).

Syntax

sys.remote_exec(pid, script)

The call returns at once, and nothing tells you when or whether the script ran: the file must still exist when the target reads it. Both interpreters must share the minor version (3.14 with 3.14), and pre-releases must match exactly. You need OS permission to access the other process's memory, and the target may forbid attaching (see is_remote_debug_enabled). Do not try it on someone else's process for fun: the code runs in its main thread.

Examples

import os, sys
with open('probe.py', 'w', encoding='utf-8') as f:
    f.write('print("привет из отладчика")\n')
ready = hasattr(sys, 'remote_exec') and sys.is_remote_debug_enabled()
print(ready)  # → ? True — 3.14 и подключение не запрещено
print(os.path.exists('probe.py'))  # → True
# sys.remote_exec(target_pid, os.path.abspath('probe.py')) — только на свой процесс

See also

Open in the full glossarydocs.python.orgReport an inaccuracy