Skip to content

Isolating execution via separate contexts #208

Open
@mashdragon

Description

@mashdragon

Describe your feature request here.

It does not seem like there is a feature in PythonMonkey to run JavaScript scripts or evals in isolation after importing the module. This means that I have to keep track of the JavaScript state myself and perform any cleanup manually on objects that pollute the globalThis space.

It would be nice if there were a way to isolate execution so that separate scripts run in separate environments, just like how scripts in the web are isolated to their pages.

Maybe this would appear as a pm.context() function to get a new JavaScript execution context.

Code example

import pythonmonkey as pm

# Potential implementation of this context feature
context = pm.context()
context.eval("x = 4")

# A different context
context2 = pm.context()
context2.eval("x = 5")

print(context.eval("x")) # Prints 4
print(context2.eval("x")) # Prints 5

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions