Skip to content

Problems with WasmExecutor #26

@flexyyyapk213

Description

@flexyyyapk213

In the 'WasmExecutor' class, I found miscalculations in the code.

  1. def exec(self, code: str, globals: dict = {}, locals: dict = {}):
    Mutable default arguments are generated, which is considered an error because they can be shared between calls.
    My proposal:
def exec(self, code: str, globals: Optional[dict] = None, locals: Optional[dict] = None):
    if globals is None:
        globals = {}
    if locals is None:
        locals = {}
  1. exec_code = f'exec("""{dedent(code)}""", {globals}, {locals})'
    If the user passes:
    """
    import os
    """
    The string will break.
    My proposal:
import json
# ...
exec_code = f'exec({json.dumps(dedent(code), ensure_ascii=False)}, {globals}, {locals})'

json handles this correctly
3. self.config.argv = ("python", "-c", exec_code)
This is bad because it is slow and consumes a lot of resources in terms of memory.
I propose loading the python runtime and keeping it alive until the instance is destroyed or keeping it as a class attribute so it is created once and for all.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions