sagemathinc / cowasm

CoWasm: Collaborative WebAssembly for Servers and Browsers. Built using Zig. Supports Python with extension modules, including numpy.
https://cowasm.org
BSD 3-Clause "New" or "Revised" License
477 stars 23 forks source link

Resubmitting the script to the Python interpreter #73

Open xozzslip opened 2 weeks ago

xozzslip commented 2 weeks ago

Context: I run a Python script in a browser environment and need advice on how to resubmit it to the Python interpreter after making updates. Here’s how I currently handle it: Original Script:

print("Hello World!")
while True:
    pass

Current Execution Method: I execute this script in the browser using the following JavaScript code:

await python.terminal(["python", "-i", "-c", code]);

Issue: After modifying the script, I need to reload and run the updated version. I was considering using the SIGKILL signal to terminate the existing session and then reinitialize it with the new script. However, I discovered that SIGKILL is not supported—only SIGINT is available. Current Non-Working Code:

python.kernel.signal(SIGKILL); // SIGKILL is not supported
await python.init();
await python.terminal(["python", "-i", "-c", newCode]);  // Intended to resubmit the new version

Questions:

  1. Given that SIGKILL is not supported and only SIGINT is available, how can I effectively terminate the existing Python session and start a new one with the updated script?
  2. Is adding support for SIGKILL a good approach to this problem?
williamstein commented 2 weeks ago

I was the only person that worked on this project, and I haven't had time to work on it for a while, so it's unlikely you'll get an answer here. Sorry about that.

xozzslip commented 2 weeks ago

Sure, no problem. I will tinker with it myself. Thank you for your effort in this project, by the way.

williamstein commented 2 weeks ago

You're welcome. I hope I can contribute to it again someday. In the meantime, if you figure out anything useful, please feel free to comment here or create a PR (e.g., improving docs, the README, etc.)