Skip to content

sys.remote_exec() scripts run in the __main__ namespace #132859

Closed
@godlygeek

Description

@godlygeek

Bug report

Bug description:

The scripts injected by sys.remote_exec run in the context of the __main__ module, meaning that they unintentionally overwrite variables used in the main script. For instance, given a loop_forever.py containing:

import os
print(os.getpid())

x = 1
while x == 1:
    pass

print(f"{x=}")

and an injected.py containing:

x = 42

Using sys.remote_exec() to inject injected.py into an interpreter running loop_forever.py results in x=42 being printed out and the script exiting.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixestype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions