-
Notifications
You must be signed in to change notification settings - Fork 1
Problems with WasmExecutor #26
Copy link
Copy link
Open
Description
In the 'WasmExecutor' class, I found miscalculations in the code.
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 = {}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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels